wbt_ph
20th September 2006, 07:05
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:
trans(QWidget *parent = 0);
public slots:
...
void showTable(QSqlQueryModel *model);
void initializeModel(QSqlQueryModel *model);
...
private:
QSqlQueryModel *model;
...
};
#endif
trans.cpp
#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();
}
main.cpp
#include <QApplication>
#include "trans.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
trans *dialog = new trans;
dialog->show();
return app.exec();
}
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.:confused:
Thank you in advance.
wil
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:
trans(QWidget *parent = 0);
public slots:
...
void showTable(QSqlQueryModel *model);
void initializeModel(QSqlQueryModel *model);
...
private:
QSqlQueryModel *model;
...
};
#endif
trans.cpp
#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();
}
main.cpp
#include <QApplication>
#include "trans.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
trans *dialog = new trans;
dialog->show();
return app.exec();
}
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.:confused:
Thank you in advance.
wil