Results 1 to 15 of 15

Thread: How can I access public variable parent Form

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 370 Times in 336 Posts

    Default Re: How can I access public variable parent Form

    if modify second approch you can get more perfomance on compilation stage, i.e. if ui-file has been modified then only needed cpp file will be rebuild. this approach is very usefull in big project with many ui-files.
    Qt Code:
    1. //h-file
    2. #include <QWidget>
    3.  
    4. namespace Ui {
    5. class MyWidget;
    6. };
    7.  
    8. class MyWidget: public QWidget
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13. MyWidget(QWidget *parent = 0);
    14. virtual ~MyWidget();
    15.  
    16. private:
    17. Ui::MyWidget *m_ui;
    18. };
    19.  
    20. //cpp-file
    21. #include "mywidget.h"
    22. #include "ui_mywidget.h"
    23.  
    24. MyWidget::MyWidget(QWidget *parent)
    25. : QWidget(parent)
    26. {
    27. m_ui = new Ui::MyWidget;
    28. m_ui->setupUi(this);
    29. }
    30.  
    31. MyWidget::~MyWidget()
    32. {
    33. delete m_ui;
    34. m_ui = 0;
    35. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  2. #2
    Join Date
    Nov 2008
    Posts
    142
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 20 Times in 20 Posts

    Default Re: How can I access public variable parent Form

    So, in general there is no real advantage in any of the two first approaches, except that it's probably easiser to modify the second one to the third that you posted?

    The third approach looks very interesting, I guess it can save quite some compile time while developing an application.

  3. #3
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 370 Times in 336 Posts

    Default Re: How can I access public variable parent Form

    Yes the third one is usefull when you have a lot of ui files
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  4. #4
    Join Date
    Nov 2008
    Posts
    142
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 20 Times in 20 Posts

    Default Re: How can I access public variable parent Form

    I see that I always wondered what the difference between the first two ones was, but it just seems to be a matter of taste Thanks for clarifying that, and for pointing out the third one. I have to keep that one in mind, it might come in handy some day

Similar Threads

  1. Link Errors
    By magikalpnoi in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2006, 23:04

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.