Set class for database connection
HI I am a beginner in Gui development using qt.
I have a project where I have to use a mysql database. I want to know how to create a class for my connection to the database and for the query so It will be easy for me to call this class in the different windows and execute sql queries
Did you take a look at the QtSql module documentation and examples ?
Yeah I did. I created an header file called connection for the connection to the database as follows
static bool connOpen()
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
qDebug()<<("Failed to open the database");
qDebug()<<("Connected"); return true;
I am able to add in my database but when I trying to display in a dialog windows using a table view, nothings shows in my table view
How are you setting up your model ?