Results 1 to 9 of 9

Thread: convoluted GUI

  1. #1
    Join Date
    Mar 2007
    Location
    Vienna / Austria
    Posts
    54
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default convoluted GUI

    Got a problem; look:

    main.cpp
    Qt Code:
    1. #include <QApplication>
    2.  
    3. #include "usc_sip_api.h"
    4. #include "usc_gui.h"
    5. #include "usc_gateway.h"
    6.  
    7. GatewayUnit *uscGatewayUnit = new GatewayUnit(0);
    8.  
    9. int main(int argc, char *argv[])
    10. {
    11. init_sip();
    12.  
    13. QApplication uscApp(argc, argv);
    14. UscGuiES1 uscGui;
    15. uscGui.show();
    16.  
    17. return uscApp.exec();
    To copy to clipboard, switch view to plain text mode 
    }

    usc_gui.cpp
    Qt Code:
    1. #include <QPalette>
    2. #include <QtGui>
    3.  
    4. #include "usc_gui.h"
    5. #include "usc_radio_element.h"
    6. #include "usc_gateway.h"
    7.  
    8. UscGuiES1::UscGuiES1(QWidget *parent)
    9. : QWidget(parent)
    10. {
    11. UscRadioElement uscRadioElement;
    12. uscRadioElement.show();
    13.  
    14. setWindowTitle(tr("Universal SIP Client"));
    15. }
    To copy to clipboard, switch view to plain text mode 

    usc_radio_element.cpp
    Qt Code:
    1. #include <QPalette>
    2. #include <QtGui>
    3.  
    4. #include "usc_gui.h"
    5. #include "usc_radio_element.h"
    6.  
    7. UscRadioElement::UscRadioElement(QWidget *parent)
    8. : QWidget(parent)
    9. {
    10. radioButton = new QPushButton(tr("R1"));
    11. rxButton = new QPushButton(tr("Rx"));
    12. txButton = new QPushButton(tr("Tx"));
    13. pttButton = new QPushButton(tr("PTT"));
    14.  
    15. QVBoxLayout *rxtxLayout = new QVBoxLayout;
    16. rxtxLayout->addWidget(rxButton);
    17. rxtxLayout->addWidget(txButton);
    18.  
    19. QHBoxLayout *topLayout = new QHBoxLayout;
    20. topLayout->addWidget(radioButton);
    21. topLayout->addLayout(rxtxLayout);
    22.  
    23. QVBoxLayout *mainLayout = new QVBoxLayout;
    24. mainLayout->addLayout(topLayout);
    25. mainLayout->addWidget(pttButton);
    26.  
    27. setLayout(mainLayout);
    28. }
    To copy to clipboard, switch view to plain text mode 

    I got no exception at compiling but my window is empty when I start the application.

    What is my mistake, what can I do to solve this problem?


    Yours Sincerely
    Walsi

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: convoluted GUI

    After setlayout( mainLayout ), try setting setFixedSize( sizeHint() );
    Just for curiosity, to see if this is the reason - the widget doesn't get resized yet.

    Then you'll know what the problem is.

    Regards

  3. #3
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: convoluted GUI

    No, forget that
    You create your buttons without a parent.
    Pass the "this" pointer as parent and everything will be OK.

    Regards

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: convoluted GUI

    Layouts handle reparenting so it should be fine.

    The reason is likely this:
    Qt Code:
    1. UscGuiES1::UscGuiES1(QWidget *parent)
    2. : QWidget(parent)
    3. {
    4. UscRadioElement uscRadioElement; // a local variable is destroyed when going out of scope
    5. uscRadioElement.show();
    6.  
    7. setWindowTitle(tr("Universal SIP Client"));
    8. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 25th April 2007 at 17:01.
    J-P Nurmi

  5. #5
    Join Date
    Mar 2007
    Location
    Vienna / Austria
    Posts
    54
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: convoluted GUI

    @ marcel: please explain a little bit more detaled what you are meaning

    @ jpn: yes and how can I handle my problem that it works???

    Best Regards,...

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: convoluted GUI

    It depends how you want it to be. Here's one way:
    Qt Code:
    1. UscGuiES1::UscGuiES1(QWidget *parent)
    2. : QWidget(parent)
    3. {
    4. UscRadioElement* uscRadioElement = new UscRadioElement(this);
    5. QVBoxLayout* layout = new QVBoxLayout(this);
    6. layout->addWidget(uscRadioElement);
    7.  
    8. setWindowTitle(tr("Universal SIP Client"));
    9. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  7. The following user says thank you to jpn for this useful post:

    Walsi (26th April 2007)

  8. #7
    Join Date
    Mar 2007
    Location
    Vienna / Austria
    Posts
    54
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: convoluted GUI

    That's exactly the solution I want. Many thanks to you!

    But my further questions, ... to come away from my newbie status, ... are following:

    Can you explain this 3 little code lines a liitle bit so that I understand it???

    Why do you define uscRadioElement as a Pointer and not like this?

    Qt Code:
    1. UscRadioElement uscRadioElement:
    To copy to clipboard, switch view to plain text mode 

    What means (this) at the uscRadioElement Definition and also at the QVBoxLayout definition??

    Best Regards!

  9. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: convoluted GUI

    Quote Originally Posted by Walsi View Post
    Can you explain this 3 little code lines a liitle bit so that I understand it???

    Why do you define uscRadioElement as a Pointer and not like this?

    Qt Code:
    1. UscRadioElement uscRadioElement:
    To copy to clipboard, switch view to plain text mode 
    A local variable allocated on the stack no more exists after the block finishes:
    Qt Code:
    1. [...]
    2. {
    3. UscRadioElement uscRadioElement;
    4. [...]
    5. } // object "uscRadioElement" no more exists
    To copy to clipboard, switch view to plain text mode 

    However,
    Qt Code:
    1. [...]
    2. {
    3. UscRadioElement* uscRadioElement = new UscRadioElement(this);
    4. [...]
    5. } // the pointer "uscRadioElement" no more exists, but the actual object remains alive
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by Walsi View Post
    What means (this) at the uscRadioElement Definition and also at the QVBoxLayout definition??
    It passes "this" as a parent for the layout. Refer to docs about QObject's parent-child relationship. When a layout is in question, it also has a special meaning that it basically calls setLayout() on the passed parent for you.
    J-P Nurmi

  10. #9
    Join Date
    Mar 2007
    Location
    Vienna / Austria
    Posts
    54
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: convoluted GUI

    thanks, that is enough explanation for me!

    Best Regards!

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.