You need to make your QTableView and QLabel part of your MainWindow. Simply creating them as standalone widgets won't work.
The rest of your code in your addEntry() method is completely messed up. I won't even try to fix it - it looks like you have no good idea what to do and are trying anything you can to get something to work. Why don't you study some of the Qt SQL examples. There are a lot of them, from basic to more advanced.
Meanwhile, here is one way to create your MainWindow (untested code, might have bugs):
MainWindow
::MainWindow( QWidget * pParent
){
labelExp->setText("first line\nsecond line");
labelExp->setAlignment(Qt::AlignBottom | Qt::AlignRight);
pLayout->addWidget( labelExp );
pLayout->addWidget( view );
pCentralWidget->setLayout( pLayout );
setCentralWidget( pCentralWidget );
// mpModel is a member variable of MainWindow
mpModel1
->setHeaderData
(0, Qt
::Horizontal,
QObject::tr("Time"));
mpModel1
->setHeaderData
(1, Qt
::Horizontal,
QObject::tr("Temperature"));
view->setModel( mpModel1 );
}
MainWindow::MainWindow( QWidget * pParent )
: QMainWindow( pParent )
{
QLabel *labelExp = new QLabel(this);
labelExp->setFrameStyle(QFrame::Panel | QFrame::Sunken);
labelExp->setText("first line\nsecond line");
labelExp->setAlignment(Qt::AlignBottom | Qt::AlignRight);
QTableView *view = new QTableView( this );
QWidget * pCentralWidget = new QWidget( this );
QVBoxLayout * pLayout = new QVBoxLayout;
pLayout->addWidget( labelExp );
pLayout->addWidget( view );
pCentralWidget->setLayout( pLayout );
setCentralWidget( pCentralWidget );
// mpModel is a member variable of MainWindow
mpModel1 = new QSqlQueryModel;
mpModel1->setHeaderData(0, Qt::Horizontal, QObject::tr("Time"));
mpModel1->setHeaderData(1, Qt::Horizontal, QObject::tr("Temperature"));
view->setModel( mpModel1 );
}
To copy to clipboard, switch view to plain text mode
Bookmarks