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);
标签:文件,Qt,对话框,setText,db,dbNameLineEdit,ui,dataBaseName From: https://www.cnblogs.com/6logic6/p/16952694.html