Results 1 to 2 of 2

Thread: QDataTable not visibility?

  1. #1
    Join Date
    Jan 2006
    Posts
    9
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default QDataTable not visibility?

    Why I not see table?

    Qt Code:
    1. class MyDB : public QWidget {
    2. Q_OBJECT
    3. public:
    4. MyDB( QWidget *parent=0, const char *name=0 ) : QWidget(parent,name) {
    5. QSqlDatabase* p = QSqlDatabase::addDatabase("QMYSQL3");
    6. p->setDatabaseName("base1");
    7. p->setUserName("root");
    8. p->setHostName("localhost");
    9. p->setPassword("123");
    10. p->open();
    11.  
    12. QSqlCursor cursor("table1");
    13. QDataTable tb(&cursor);
    14. tb.addColumn("fam","fam");
    15. tb.addColumn("name","name");
    16. tb.refresh();
    17.  
    18. }
    19. };
    20.  
    21. #include "main.moc"
    22.  
    23. int main(int a,char**b){
    24. QApplication app(a,b);
    25. MyDB db;
    26. db.setGeometry(100,100,400,300);
    27. db.show();
    28. app.setMainWidget(&db);
    29. return app.exec();
    30. }
    To copy to clipboard, switch view to plain text mode 

    if code inside MyDB(...) {} move inside main() then i am see table?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDataTable not visibility?

    Because you create it on stack and it goes out of scope and is destroyed when the constructor returns.

  3. The following user says thank you to wysota for this useful post:

    Dmitry (6th April 2006)

Similar Threads

  1. Qt4 - QSqlQueryModel x Qt3 QDataTable
    By ederbs in forum Qt Programming
    Replies: 3
    Last Post: 10th September 2007, 07:38
  2. Rollback transactions in QDataTable
    By bubba in forum Qt Programming
    Replies: 0
    Last Post: 25th July 2007, 09:41
  3. QDataTable to bloquer modified value
    By cristiano in forum Qt Programming
    Replies: 5
    Last Post: 17th January 2007, 00:58
  4. Refresh QDataTable
    By shamik in forum Qt Programming
    Replies: 25
    Last Post: 1st December 2006, 05:04
  5. displaying any table on a qdatatable
    By Philip_Anselmo in forum Newbie
    Replies: 4
    Last Post: 9th May 2006, 22:12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.