Thank you Janus, but this do not sove my problem... 
A compilable code:
#include <QApplication>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QString>
#include <QSqlTableModel>
#include <QTableView>
#include <QtGui>
#include <QtSql>
int main(int argc, char *argv[])
{
//QWidget *w = new QWidget;
db.setDatabaseName("stock.sqlite");
if (!db.
open()) QMessageBox::critical(0,
QObject::tr("Database Error"), db.
lastError().
text());
model->setTable("productes");
model->select();
tableView->setSortingEnabled(true);
tableView->setModel(model);
db.close();
tableView->show();
//w->show();
return app.exec();
}
#include <QApplication>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QString>
#include <QSqlTableModel>
#include <QTableView>
#include <QtGui>
#include <QtSql>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
//QWidget *w = new QWidget;
QTableView * tableView = new QTableView();
QSqlTableModel *model;
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("stock.sqlite");
if (!db.open()) QMessageBox::critical(0, QObject::tr("Database Error"), db.lastError().text());
model = new QSqlTableModel(tableView);
model->setTable("productes");
model->select();
tableView->setSortingEnabled(true);
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
tableView->setSelectionMode(QAbstractItemView::SingleSelection);
tableView->setModel(model);
db.close();
tableView->show();
//w->show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
this can be tried with the database attached (it is very small), i put the .txt extension to upload it, but it is in sqlite3 format.
I was trying (for one week) to use a mysql database, but I can't compile the driver, I know that are lots of threads and lots of tutorials, but I always get a compile error, is there a really working way to compile/load the mysql driver?
Bookmarks