Hello Everyone,
Well i am working on CentOS and trying to create a simple program which requires to connect with MySql.
Qt : 5
OS : CentOS
#include <QApplication>
#include <QTableWidget>
#include <QMessageBox>
#include <QtSql>
int main(int argc,char* argv[])
{
table->setWindowTitle("Connect to Mysql Database Example");
db.setHostName("192.168.11.3");
db.setDatabaseName("menudb");
db.setUserName("root");
db.setPassword("test");
if (!db.open())
{
db.lastError().text());
}
table->setColumnCount(query.record().count());
table->setRowCount(query.size());
int index=0;
while (query.next())
{
index++;
}
table->show();
return app.exec();
}
#include <QApplication>
#include <QTableWidget>
#include <QMessageBox>
#include <QtSql>
int main(int argc,char* argv[])
{
QApplication app(argc,argv);
QTableWidget* table = new QTableWidget();
table->setWindowTitle("Connect to Mysql Database Example");
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("192.168.11.3");
db.setDatabaseName("menudb");
db.setUserName("root");
db.setPassword("test");
if (!db.open())
{
QMessageBox::critical(0, QObject::tr("Database Error"),
db.lastError().text());
}
QSqlQuery query("SELECT * FROM test");
table->setColumnCount(query.record().count());
table->setRowCount(query.size());
int index=0;
while (query.next())
{
table->setItem(index,0,new QTableWidgetItem(query.value(0).toString()));
table->setItem(index,1,new QTableWidgetItem(query.value(1).toString()));
index++;
}
table->show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Well the problem is MySql DRIVERS are not loaded.
Which drivers should i use in CentOS to connect my program with MySql?
Bookmarks