QTableView shows nothing
-
Where is the piece of code ? Is it in main function or somewhere else ?
Could be because query object is stack object. Try allocating in Heap. -
Where is the piece of code ? Is it in main function or somewhere else ?
Could be because query object is stack object. Try allocating in Heap.@dheerendra said in QTableView shows nothing:
Where is the piece of code ? Is it in main function or somewhere else ?
Could be because query object is stack object. Try allocating in Heap.Thanks problem solved :)
How to know, when allocate in Heap and when as stack object?
-
@dheerendra said in QTableView shows nothing:
Where is the piece of code ? Is it in main function or somewhere else ?
Could be because query object is stack object. Try allocating in Heap.Thanks problem solved :)
How to know, when allocate in Heap and when as stack object?
-
Hi,
To add to my fellow, you are also not checking whether the database is opened correctly.
-
Hi,
To add to my fellow, you are also not checking whether the database is opened correctly.
@SGaist said in QTableView shows nothing:
Hi,
To add to my fellow, you are also not checking whether the database is opened correctly.
I am checking
if(db.open()) {
but i didnt include it in post :) but thank you anyway :)
@mrjj said in QTableView shows nothing:
void mainwindow::some func() {
MyClass C; // stack
MyClass *D = new MyClass; // heap} // here C will be deleted. ( runs out of scope) BUT D lives until deleted by programmer.
So when using new, you are using heap.
yes i know, but i dont know when use pointer and when stack
-
@SGaist said in QTableView shows nothing:
Hi,
To add to my fellow, you are also not checking whether the database is opened correctly.
I am checking
if(db.open()) {
but i didnt include it in post :) but thank you anyway :)
@mrjj said in QTableView shows nothing:
void mainwindow::some func() {
MyClass C; // stack
MyClass *D = new MyClass; // heap} // here C will be deleted. ( runs out of scope) BUT D lives until deleted by programmer.
So when using new, you are using heap.
yes i know, but i dont know when use pointer and when stack
@t0msk said in QTableView shows nothing:
i dont know when use pointer and when stack
Well use stack when possible.
If the variable is to be used outside a function/live longer than the function where its declared , consider using new or adding it as a member variable. -
@t0msk said in QTableView shows nothing:
i dont know when use pointer and when stack
Well use stack when possible.
If the variable is to be used outside a function/live longer than the function where its declared , consider using new or adding it as a member variable.@mrjj said in QTableView shows nothing:
@t0msk said in QTableView shows nothing:
i dont know when use pointer and when stack
Well use stack when possible.
If the variable is to be used outside a function/live longer than the function where its declared , consider using new or adding it as a member variable.yea, so I have to use "new" always, because everything is function :D ,
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
Is function too (my problem) :D
-
@mrjj said in QTableView shows nothing:
@t0msk said in QTableView shows nothing:
i dont know when use pointer and when stack
Well use stack when possible.
If the variable is to be used outside a function/live longer than the function where its declared , consider using new or adding it as a member variable.yea, so I have to use "new" always, because everything is function :D ,
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
Is function too (my problem) :D
@t0msk
Yes
You do
QSqlQueryModel query;
..
ui->tableView->setModel(&query);Here you use & to take adress of it.
So as soon as function ends query is deleted and view is empty.
You could move
QSqlQueryModel query; to .h file.
as member in mainwindow -
@t0msk
Yes
You do
QSqlQueryModel query;
..
ui->tableView->setModel(&query);Here you use & to take adress of it.
So as soon as function ends query is deleted and view is empty.
You could move
QSqlQueryModel query; to .h file.
as member in mainwindow@mrjj said in QTableView shows nothing:
@t0msk
Yes
You do
QSqlQueryModel query;
..
ui->tableView->setModel(&query);Here you use & to take adress of it.
So as soon as function ends query is deleted and view is empty.
You could move
QSqlQueryModel query; to .h file.
as member in mainwindowAh, thank you for explanation :)