1. 程式人生 > 其它 >Qt+vs讀取檔案(檔案對話方塊問題)

Qt+vs讀取檔案(檔案對話方塊問題)

Qt Creator檔案定位正確,VS2010+QT定位失敗:
//選擇資料庫名稱
void dbSettingDlg::on_selectBtn_clicked()
{
    QString dataBaseName = QFileDialog::getOpenFileName(this,QStringLiteral("選擇資料庫"),
                                    "./",QStringLiteral("資料庫檔案(*db);"));
    if(dataBaseName.isEmpty())
        ui->dbNameLineEdit->setText(cIni->value("db/dbName").toString());
    else
        ui->dbNameLineEdit->setText(dataBaseName);

}
在VS2010解決方法:
QString path = QApplication::applicationDirPath();
QFileDialog fileDialog(this,tr("選擇資料庫"),path,tr("dbFile(*.db)"));
fileDialog.exec();///////////////////////////////////////////////////////////此時可出現檔案對話方塊,檔案的定位位置也正確
QStringList dataBaseName = fileDialog.selectedFiles();//獲取到所選擇的檔案絕對路徑名字

  if(dataBaseName.isEmpty())
        ui->dbNameLineEdit->setText(cIni->value("db/dbName").toString());
    else
        ui->dbNameLineEdit->setText(dataBaseName);