Results 1 to 3 of 3

Thread: Multiple form object creation

  1. #1
    Join Date
    Jan 2009
    Posts
    14
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Exclamation Multiple form object creation

    Hello guys!

    In my project i need to invoke mutiple ui files. I tried QWizard, but it leads to fail. So i used QUiLoader. Consider my example, ( I am using the QT-Designer 4.4 for creating ui )

    testform.h

    Qt Code:
    1. class form1: public QWidget
    2. {
    3. ....
    4. ....
    5. ....
    6. };
    7.  
    8. class form2: public QWidget
    9. {
    10. ....
    11. ....
    12. ....
    13. };
    To copy to clipboard, switch view to plain text mode 

    testform.cpp

    Qt Code:
    1. form1::form1(QWidget *parent): QWidget(parent)
    2. {
    3. QUiLoader loader;
    4.  
    5. QFile file(":/form1.ui");
    6. file.open(QFile::ReadOnly);
    7. QWidget *formWidget = loader.load(&file, this);
    8. file.close();
    9.  
    10. ui_inputSpinBox1 = qFindChild<QSpinBox*>(this, "inputSpinBox1");
    11.  
    12. QMetaObject::connectSlotsByName(this);
    13.  
    14. QVBoxLayout *layout = new QVBoxLayout;
    15. layout->addWidget(formWidget);
    16. setLayout(layout);
    17. }
    18.  
    19. testform::testform(QWidget *parent): QWidget(parent)
    20. {
    21. QMessageBox::information(this,tr("test"),tr("test"),QMessageBox::Ok);
    22. QUiLoader loader;
    23.  
    24. QFile file(":/testform.ui");
    25. file.open(QFile::ReadOnly);
    26. QWidget *formWidget = loader.load(&file, this);
    27. file.close();
    28. QVBoxLayout *layout = new QVBoxLayout;
    29. layout->addWidget(formWidget);
    30. setLayout(layout);
    31. }
    32.  
    33. void form1::on_inputSpinBox1_valueChanged(int value)
    34. {
    35. this->hide(); // form1 hide method called successfully
    36. form2 form2_object;
    37. form2.show(); // This object created and as soon as closed
    38. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication app(argc, argv);
    4. form1 form1_object;
    5. form1.show();
    6. return app.exec();
    7. }
    To copy to clipboard, switch view to plain text mode 

    My question is how to create a object for form2 from form1 method. Or else how to invoke
    the form2 object from form1 method. Please help me guys.... Sorry for
    such a lengthy thread.... Any hint can be Appreciated.

    Advance thanks!

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

    Default Re: Multiple form object creation

    Include "form2.h" from "form1.cpp" and use "new form2(...)" to create the widget. It's just plain C++ you know...

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

    kpmsivachand (3rd February 2009)

  4. #3
    Join Date
    Jan 2009
    Posts
    14
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Multiple form object creation

    Thanks for your reply... Let me try out...

Similar Threads

  1. Object and multiple inheritance for interfaces
    By brcain in forum Qt Programming
    Replies: 8
    Last Post: 29th June 2021, 15:29
  2. Multiple form management?
    By kpmsivachand in forum Qt Programming
    Replies: 3
    Last Post: 31st January 2009, 06:40
  3. A form returning an object.
    By cbarmpar in forum Qt Programming
    Replies: 3
    Last Post: 8th September 2008, 05:21
  4. Passing an object from one form to the other.
    By cbarmpar in forum Qt Programming
    Replies: 10
    Last Post: 3rd September 2008, 14:12
  5. Designer form creation very slow
    By MrGarbage in forum Qt Programming
    Replies: 3
    Last Post: 7th December 2007, 22:20

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.