Results 1 to 9 of 9

Thread: can't get a simple dialog working

  1. #1
    Join Date
    Jan 2006
    Location
    Cincinnati, Ohio, USA
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Angry can't get a simple dialog working

    I was trying to make a simple dialog and use the multiple inheritance method to make it work. But I can't get it going. The dialog is called "handmade.ui". The ui_handmade.h file is being generated ok.

    The latest error is:
    main.cpp:29: error: 'class Ui::handmade' has no member named 'show'
    I'm lost. My "handmade" dialog inherits from QDialog which inherits QWidget which contains the show() function. What gives?

    Am I including things in the wrong places?

    Here's my code.
    main.cpp
    Qt Code:
    1. #include "ui_handmade.h"
    2. #include <QApplication>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication app(argc, argv);
    7. Ui::handmade *dialog = new Ui::handmade;
    8.  
    9. dialog->show(); // <- Error occurs here
    10. return app.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    handmade.h
    Qt Code:
    1. #ifndef HANDMADE_H
    2. #define HANDMADE_H
    3.  
    4. #include "ui_handmade.h"
    5.  
    6. class handmade : public QDialog, private Ui::handmade
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. handmade(QWidget* parent = 0);
    12. ~handmade();
    13. /*$PUBLIC_FUNCTIONS$*/
    14.  
    15. public slots:
    16. /*$PUBLIC_SLOTS$*/
    17.  
    18. protected:
    19. /*$PROTECTED_FUNCTIONS$*/
    20.  
    21. protected slots:
    22. /*$PROTECTED_SLOTS$*/
    23.  
    24. };
    25.  
    26. #endif
    To copy to clipboard, switch view to plain text mode 

    handmade.cpp
    Qt Code:
    1. #include "handmade.h"
    2.  
    3. handmade::handmade(QWidget* parent) : QDialog(parent)
    4. {
    5. setupUi(this);
    6. connect(ctrSlider, SIGNAL(valueChanged()), displayLCD, SLOT(display()));
    7. show(this);
    8. }
    9.  
    10. handmade::~handmade()
    11. {}
    To copy to clipboard, switch view to plain text mode 

    Thanks,
    Paul

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: can't get a simple dialog working

    try just show()

  3. #3
    Join Date
    Jan 2006
    Location
    Cincinnati, Ohio, USA
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: can't get a simple dialog working

    Perhaps you could be more specific.

    I tried:
    I changed dialog->show() to show() in main.cpp, recompiled and it said show() was undefined (compile error). That one I understand.

    I commented out the show() function in main.cpp and left show(this) in handmade.cpp uncommented. Compile error: handmade.cpp:29: error: no matching function for call to `handmade::show(handmade* const)

    I change the function to just plain old show() in handmade.cpp, compiles fine. However, I never see the dialog box when it runs and have to kill the task. I also get a warning: main.cpp:27: warning: unused variable 'dialog'

    What else am I missing?
    Paul

  4. #4
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: can't get a simple dialog working

    Thomas,

    The error is in main function

    Qt Code:
    1. Ui::handmade *dialog = new Ui::handmade
    To copy to clipboard, switch view to plain text mode 

    instead include the handmade.h in the main and
    then make object of that.
    Call the show now

    Also you can see the ui_handmade.h for why there is no show in the Ui::handmade
    We can't solve problems by using the same kind of thinking we used when we created them

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    52
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Cool Re: can't get a simple dialog working

    If I read your code in the main function correctly, then you're including the wrong header. You include the header that was generated by the uic compiler for your dialog resource.
    However as correctly done, you created a dialog class that inherits from the uic generated class. Your class correctly inherits QDialog, and with that comes the show() method. However now it seems that you're not using your own class in the main method. Try doing this instead:

    Qt Code:
    1. #include "handmade.h" // <-- Use your own dialog class
    2. #include <QApplication>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication app(argc, argv);
    7. // Create an instance of your own dialog
    8. handmade *dialog = new handmade;
    9.  
    10. dialog->show();
    11. return app.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    Then your dialog should work as expected.

    Ups, I think it was answered just before...
    Last edited by Mike; 13th January 2006 at 08:35.

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    52
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: can't get a simple dialog working

    Another thing I noticed. In the constructor of your own "handmade" dialog class you invoke show(). I don't think you are suppose to do that. Normally you want to setup the dialog, set some additional stuff, maybe invoke an init method, and only then, in the calling method,
    Qt Code:
    1. handmade->show()
    To copy to clipboard, switch view to plain text mode 
    or for a modal dialog
    Qt Code:
    1. handmade->exec()
    To copy to clipboard, switch view to plain text mode 
    should be invoked. Does this make sense to you?

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

    Default Re: can't get a simple dialog working

    Quote Originally Posted by pthomas
    The latest error is:
    I'm lost. My "handmade" dialog inherits from QDialog which inherits QWidget which contains the show() function. What gives?

    It is the QDialog which inherits QWidget. UI::xxxx doesn't.

  8. #8
    Join Date
    Jan 2006
    Location
    Cincinnati, Ohio, USA
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: can't get a simple dialog working [Solved]

    I think I understand this all much better now. I tried what you guys suggested and got it working...a working dialog is such a beautiful site

    So my thinking was quite backwards. I was inheriting the ui_* created header file and trying to create my object with it. It now makes sense that I needed to call my extended class 'handmade.h' since IT inherits the ui_handmade.h file and QDialog.

    Thanks for the help everyone,
    Paul

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: can't get a simple dialog working

    Similar problem was discussed here.

Similar Threads

  1. Issue with Modelless dialog on Mac
    By Satyanarayana Chebrolu in forum Qt Programming
    Replies: 0
    Last Post: 24th February 2009, 10:10
  2. Dialog is not closing
    By manmohan in forum Newbie
    Replies: 5
    Last Post: 1st December 2008, 17:04
  3. Replies: 9
    Last Post: 13th August 2008, 18:07
  4. Resizing the dialog boxes
    By anju123 in forum Qt Programming
    Replies: 4
    Last Post: 14th September 2007, 10:41
  5. dialog box
    By Bahar in forum Qt Programming
    Replies: 3
    Last Post: 31st January 2006, 14:52

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.