Page 5 of 6 FirstFirst ... 3456 LastLast
Results 81 to 100 of 105

Thread: Problem displaying my main window

  1. #81
    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: Problem displaying my main window

    So the answer is no, you don't define slots

  2. #82
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem displaying my main window

    Thanks And I've got one more question, why some slots are defined in private slots and some are defined in private? Both are private sections of MainWindow class, what's the difference?

  3. #83
    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: Problem displaying my main window

    C++ access qualifiers public, protected and private (refer to you favourite C++ book for more explanation) apply to slots as well.

    A slot is not a C++ but a Qt term. A normal C++ function is not a slot but a slot is a function. That is, a normal C++ function cannot be used as a slot in a connect statement but a slot can be called like a normal C++ function. A function needs to be explicitly declared as a slot to be able to use it as a slot. So there are no "slots defined in private slots" and "slots defined in private". Only the former are slots.
    J-P Nurmi

  4. #84
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem displaying my main window

    So we define slots in private slots, and standard cpp functioms in private, right?

  5. #85
    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: Problem displaying my main window

    Yes, that's right.

  6. #86
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem displaying my main window

    And in maker.cpp I have to do the same what I was doing with MainWindow:
    Qt Code:
    1. MainWindow::MainWindow(QMainWindow *parent)
    2. : QMainWindow(parent)
    3. {
    4. ui.setupUi(this);
    5.  
    6. }
    7.  
    8. void MainWindow::on_actionAbout_triggered()
    9. {
    10.  
    11.  
    12. Dialog dlg( this );
    13.  
    14.  
    15.  
    16. dlg.exec();
    17.  
    18.  
    19.  
    20. }
    To copy to clipboard, switch view to plain text mode 
    but without implementing slots, right?

  7. #87
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem displaying my main window

    I have a problem. I've implemented this:
    Maker.h
    Qt Code:
    1. #ifndef MAKER_H
    2. #define MAKER_H
    3.  
    4. #include "ui_maker.h"
    5.  
    6.  
    7.  
    8. class MainWindow : public QMainWindow, public Ui::MainWindow
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13. MainWindow(QMainWindow *parent = 0);
    14.  
    15. private slots:
    16.  
    17. void on_actionAbout_triggered();
    18.  
    19. private:
    20.  
    21. Ui::MainWindow ui;
    22. };
    23.  
    24. #endif
    To copy to clipboard, switch view to plain text mode 

    About.h
    Qt Code:
    1. #ifndef ABOUT_H
    2. #define ABOUT_H
    3.  
    4. #include "ui_about.h"
    5.  
    6.  
    7.  
    8. class Dialog : public QDialog, public Ui::Dialog
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13. Dialog(QDialog *parent = 0);
    14.  
    15.  
    16. private:
    17.  
    18. Ui::Dialog ui;
    19. };
    20.  
    21. #endif
    To copy to clipboard, switch view to plain text mode 

    Maker.cpp
    Qt Code:
    1. #include <QtGui>
    2.  
    3. #include "maker.h"
    4. #include "about.h"
    5.  
    6. MainWindow::MainWindow(QMainWindow *parent)
    7. : QMainWindow(parent)
    8. {
    9. ui.setupUi(this);
    10.  
    11. }
    12.  
    13. void MainWindow::on_actionAbout_triggered()
    14. {
    15.  
    16.  
    17. Dialog dlg( this );
    18.  
    19.  
    20.  
    21. dlg.exec();
    22.  
    23.  
    24.  
    25. }
    26.  
    27.  
    28.  
    29.  
    30. Dialog::Dialog(QDialog *parent)
    31. : QDialog(parent)
    32. {
    33. ui.setupUi(this);
    34.  
    35. }
    To copy to clipboard, switch view to plain text mode 

    And also main.cpp, which contents I won't post, because it's obvious. And there appear errors:
    maker.cpp:in member function 'void MainWindow:n_actionAbout_triggered()':
    maker.cpp:17:error: no matching function for call to 'Dialog:ialog(MainWindow* const)
    about.h:9:note: candidates are Dialog:ialog(const Dialog&)
    about.h:13:note: Dialog:ialog(QDialog*)

    What's wrong? I thought I'd done everything as it was described in C++ GUI and in this topic. Regards
    p.s.
    Forum mechanism replaced : D with a smile and also : o with the other smile, as you seen so far

  8. #88
    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: Problem displaying my main window

    Quote Originally Posted by Salazaar View Post
    What's wrong? I thought I'd done everything as it was described in C++ GUI and in this topic.
    It should be:
    Qt Code:
    1. class Dialog ...
    2. {
    3. ...
    4. Dialog(QWidget *parent = 0); // notice the type of the parent
    5. ...
    6. };
    To copy to clipboard, switch view to plain text mode 
    The dialog of yours demands a QDialog as a parent. QMainWindow is not a QDialog but both are QWidgets.
    J-P Nurmi

  9. #89
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem displaying my main window

    I replaced QDialog with QWidget but it didn't solve the problem:

    maker.cpp:31:error: Prototype for Dialog:ialog(QDialog*) does not match any in class Dialog
    about.h:9:error: candidates are Dialogialog(const Dialog&)
    about:.h:13:error Dialog:ialog(QWidget*)

    What's wrong now? Regards

  10. #90
    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: Problem displaying my main window

    Most likely you forgot to change it in the .cpp file too.
    J-P Nurmi

  11. #91
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem displaying my main window

    Yes, now I changed it into cpp file too, but there appear error:
    maker.cpp: In constructor Dialog:ialog(QWidget*)
    maker.cpp:31:error: Type 'class QWidget' is not a direct base of Dialog

    What's wrong, now? Regards,

  12. #92
    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: Problem displaying my main window

    Edit: No, wait. I don't want to spoon-feed the solution.

    A parent and a base class are different things. You changed the parent correctly, but you are now calling a wrong base class. Just think of it yourself.
    Last edited by jpn; 2nd June 2007 at 06:48.
    J-P Nurmi

  13. #93
    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: Problem displaying my main window

    Quote Originally Posted by Salazaar View Post
    p.s.
    Forum mechanism replaced : D with a smile and also : o with the other smile, as you seen so far
    You can use code or qtclass tags or check the "Disable smilies in text" tick to overcome that.

  14. #94
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem displaying my main window

    Quote Originally Posted by jpn View Post
    Edit: No, wait. I don't want to spoon-feed the solution.

    A parent and a base class are different things. You changed the parent correctly, but you are now calling a wrong base class. Just think of it yourself.
    So, leave QWidget as I changed it after your advice? I thought about calling wrong base class, but I didn't find the problem. Regards

  15. #95
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem displaying my main window

    I forgot to change one of QDialog to QWidget, but there still are problems;
    here is original log of compilation:
    http://allyoucanupload.webshots.com/...70322826506289

  16. #96
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem displaying my main window

    Do you know why it doesn't work?

  17. #97
    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: Problem displaying my main window

    Does class "Dialog" inherit QDialog?

  18. #98
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem displaying my main window

    Yes, I think so. Here are the files
    Maker.h
    Qt Code:
    1. #ifndef MAKER_H
    2. #define MAKER_H
    3.  
    4. #include "ui_maker.h"
    5.  
    6.  
    7.  
    8. class MainWindow : public QMainWindow, public Ui::MainWindow
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13. MainWindow(QMainWindow *parent = 0);
    14.  
    15. private slots:
    16.  
    17. void on_actionAbout_triggered();
    18.  
    19. private:
    20.  
    21. Ui::MainWindow ui;
    22. };
    23.  
    24. #endif
    To copy to clipboard, switch view to plain text mode 

    About.h
    Qt Code:
    1. #ifndef ABOUT_H
    2. #define ABOUT_H
    3.  
    4. #include "ui_about.h"
    5.  
    6.  
    7.  
    8. class Dialog : public QWidget, public Ui::Dialog
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13. Dialog(QWidget *parent = 0);
    14.  
    15.  
    16. private:
    17.  
    18. Ui::Dialog ui;
    19. };
    20.  
    21. #endif
    To copy to clipboard, switch view to plain text mode 

    Maker.cpp
    Qt Code:
    1. #include <QtGui>
    2.  
    3. #include "maker.h"
    4. #include "about.h"
    5.  
    6. MainWindow::MainWindow(QMainWindow *parent)
    7. : QMainWindow(parent)
    8. {
    9. ui.setupUi(this);
    10.  
    11. }
    12.  
    13. void MainWindow::on_actionAbout_triggered()
    14. {
    15.  
    16.  
    17. Dialog dlg( this );
    18.  
    19.  
    20.  
    21. dlg.exec();
    22.  
    23.  
    24.  
    25. }
    26.  
    27.  
    28.  
    29.  
    30. Dialog::Dialog(QWidget *parent)
    31. : QWidget(parent)
    32. {
    33. ui.setupUi(this);
    34.  
    35. }
    To copy to clipboard, switch view to plain text mode 
    And also main.cpp, ui_about.h, ui_maker.h which contents are obvious. So, what's wrong in it? Regards

  19. #99
    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: Problem displaying my main window

    Quote Originally Posted by Salazaar View Post
    So, what's wrong in it?
    The compiler told you what's wrong.

    Dialog isn't derived directly from QWidget, so you can't invoke QWidget constructor, so this:
    Qt Code:
    1. Dialog::Dialog(QWidget *parent)
    2. : QWidget(parent)
    3. {
    4. ...
    To copy to clipboard, switch view to plain text mode 

    should be:
    Qt Code:
    1. Dialog::Dialog( QWidget *parent )
    2. : QDialog( parent )
    3. {
    4. ...
    To copy to clipboard, switch view to plain text mode 

  20. #100
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem displaying my main window

    I've done it, but it didn't solve the problem. Compilation log:
    http://allyoucanupload.webshots.com/...74960843080783
    Regards

Similar Threads

  1. Replies: 15
    Last Post: 23rd March 2007, 16:16
  2. move parent window to the front.
    By hvengel in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2007, 08:41
  3. Problem in porting Main window on linux
    By jyoti kumar in forum Qt Tools
    Replies: 2
    Last Post: 2nd June 2006, 08:35
  4. cannot make a main window modal
    By Dark_Tower in forum Qt Programming
    Replies: 12
    Last Post: 23rd March 2006, 10:21
  5. Main window
    By Michiel in forum Qt Tools
    Replies: 1
    Last Post: 20th March 2006, 23:54

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.