Results 1 to 14 of 14

Thread: QUiLoader flawed/not providing name for Layouts. Workaround?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Sep 2006
    Posts
    19
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QUiLoader flawed/not providing name for Layouts. Workaround?

    Thanks, when doing this I get a pointer back rather than 0, however the application still crashes when trying to add my QScrollArea to the layout. Any hints?

    EDIT: First time I tried layout() on the central widget I got a valid pointer, but consecutive runs yield a 0 pointer like previously :S

    Main
    Qt Code:
    1. int main(int arg_count, char **arg_list)
    2. {
    3. QApplication juliet(arg_count, arg_list);
    4. QApplication::setStyle(new QPlastiqueStyle);
    5.  
    6. mainwindow ui;
    7. ui.show();
    8.  
    9. return juliet.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 


    Class header
    Qt Code:
    1. class mainwindow:public QMainWindow
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6.  
    7. mainwindow();
    8.  
    9. QScrollArea *render_window;
    10. QLabel *label_render;
    11. QGridLayout *render_layout;
    12.  
    13. ...
    14.  
    15. };
    To copy to clipboard, switch view to plain text mode 


    Class implementation
    Qt Code:
    1. mainwindow::mainwindow()
    2. {
    3. QUiLoader loader;
    4. QFile file(":/interface/juliet.ui");
    5. file.open(QFile::ReadOnly);
    6. QWidget *central = loader.load(&file);
    7. setCentralWidget(central);
    8. file.close();
    9.  
    10. label_render = findChild<QLabel*>("label_render");
    11. render_layout = qobject_cast<QGridLayout*>(central->layout());
    12. render_window = new QScrollArea;
    13.  
    14. QPixmap pixmap(200, 200);
    15. pixmap.fill(Qt::black);
    16. label_render->setPixmap(pixmap);
    17. label_render->setAlignment(Qt::AlignCenter);
    18. render_window->setWidget(label_render);
    19. render_window->setWidgetResizable(true);
    20. render_window->setFocusPolicy(Qt::NoFocus);
    21. render_window->installEventFilter(this);
    22. render_layout->addWidget(render_window, 0, 0, 1, 4); // <-- Application crash
    23.  
    24. QMetaObject::connectSlotsByName(this);
    25. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by ZB; 30th September 2006 at 23:27.

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.