我正在处理一些数据库应用程序,并且我发现了一些让我停滞了好几天的事情。 如上所述,debuger说:
找不到
Preferences' value found>
Ui_MainWindow :: setupUi(QMainWindow *):: {lambda()#13} :: operator()()const :: qstring_literal&#39的虚拟表的链接器符号;代替
我的代码如下: MainWindow.cpp,只有一种方法:
QString MainWindow::ConnectDatabase()
{
// TODO Make Alaviability to change Database things
QSqlDatabase database = QSqlDatabase::addDatabase("QMYSQL");
Preferences pref;
std::vector <QString> preferencesVector = pref.openFromFile();
database.setHostName(preferencesVector[1]);
database.setDatabaseName(preferencesVector[2]);
database.setUserName(preferencesVector[3]);
database.setPassword(preferencesVector[4]);
if (database.isValid())
{
database.open();
return "Połączono!\n";
}
else
return "Database Error: " + database.lastError().text();
}
preference.cpp中的首选项类:
Preferences::Preferences(QWidget *parent) :
QDialog(parent),
ui(new Ui::Preferences)
{
ui->setupUi(this);
}
Preferences::~Preferences()
{
delete ui;
}
std::fstream Preferences::openFile()
{
std::fstream preferencesFile;
preferencesFile.open("preferencesFile.txt");
return preferencesFile;
}
std::vector<QString> Preferences::openFromFile()
{
std::string line;
std::vector <QString> preferencesVector;
std::fstream preferencesFile = openFile();
if (preferencesFile.is_open())
{
while (std::getline(preferencesFile, line))
preferencesVector.push_back(QString::fromStdString(line));
}
return preferencesVector;
}
void Preferences::saveIntoFile()
{
std::fstream preferencesFile = openFile();
if (preferencesFile.is_open())
{
preferencesFile << ui->lineEditHos;
preferencesFile << ui->lineEditDatabase;
preferencesFile << ui->lineEditUser;
preferencesFile << ui->lineEditPassword;
QMessageBox::information(NULL, "Informacja", "Plik z ustawieniami został zapisany", QMessageBox::Ok);
}
else
QMessageBox::warning(NULL, "UWAGA!", "Plik z ustawieniami nie został otwarty", QMessageBox::Ok);
preferencesFile.close();
}
bool Preferences::on_pushButtonOk_clicked()
{
saveIntoFile();
this->close();
return true;
}
提前谢谢