Hello.
I am a newbie.
here is part of my code:
trans.h
#ifndef TRANS_H
#define TRANS_H
#include <QtSql>
#include "ui_fleTrans.h"
class trans
: public QWidget,
private Ui
::frmTrans{
Q_OBJECT
public:
public slots:
...
...
private:
...
};
#endif
#ifndef TRANS_H
#define TRANS_H
#include <QtSql>
#include "ui_fleTrans.h"
class trans : public QWidget, private Ui::frmTrans
{
Q_OBJECT
public:
trans(QWidget *parent = 0);
public slots:
...
void showTable(QSqlQueryModel *model);
void initializeModel(QSqlQueryModel *model);
...
private:
QSqlQueryModel *model;
...
};
#endif
To copy to clipboard, switch view to plain text mode
trans.cpp
#include <QtGui>
#include <QtSql>
#include "trans.h"
#include "custsqlmodel.h" //basically the same as customsqlmodel in sql/querymodel
//example
{
db.setHostName("localhost");
db.setDatabaseName("databasename");
db.setUserName("username");
db.setPassword("password");
if (!db.open())
{
QMessageBox::critical(0,
"Database Error", db.
lastError().
text());
}
setupUi(this);
CustSqlModel custSqlModel;
initializeModel(&custSqlModel);
showTable(&custSqlModel);
}
{
model->setQuery("select * from table");
}
{
view->setModel(model);
view->show();
}
#include <QtGui>
#include <QtSql>
#include "trans.h"
#include "custsqlmodel.h" //basically the same as customsqlmodel in sql/querymodel
//example
trans::trans(QWidget *parent)
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setDatabaseName("databasename");
db.setUserName("username");
db.setPassword("password");
if (!db.open())
{
QMessageBox::critical(0, "Database Error", db.lastError().text());
}
setupUi(this);
model = new QSqlQueryModel;
CustSqlModel custSqlModel;
initializeModel(&custSqlModel);
showTable(&custSqlModel);
}
void trans::initializeModel(QSqlQueryModel *model)
{
model->setQuery("select * from table");
}
void trans::showTableLedger(QSqlQueryModel *model)
{
QTableView *view = new QTableView;
view->setModel(model);
view->show();
}
To copy to clipboard, switch view to plain text mode
main.cpp
#include <QApplication>
#include "trans.h"
int main(int argc, char *argv[])
{
trans *dialog = new trans;
dialog->show();
return app.exec();
}
#include <QApplication>
#include "trans.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
trans *dialog = new trans;
dialog->show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
nothing wrong with my qsqlquerysublcass since it compiles without error and shows the data in the table using the sql/querymodel example.
The above code simply shows a window frame with scroll bars, no grid, no column header, no data - just white space.
Please help.
Thank you in advance.
wil
Bookmarks