Page 4 of 6 FirstFirst ... 23456 LastLast
Results 61 to 80 of 105

Thread: Problem displaying my main window

  1. #61
    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 want to connect action in my menu called actionAbout to dialog which is in ui_about

  2. #62
    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
    I want to connect action in my menu called actionAbout to dialog which is in ui_about
    Define "connect". What exactly you want to happen?

  3. #63
    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

    if a ucer clicks a button, than about dialog is displayed

  4. #64
    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
    if a ucer clicks a button, than about dialog is displayed
    I've already shown you how to do it.

    Have you read the third chapter?

  5. #65
    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

    Right
    Qt Code:
    1. void MainWindow::on_actionAbout_triggered()
    2.  
    3. {
    4.  
    5. OtherDialog dlg( this );
    6.  
    7. dlg.exec();
    8.  
    9. }
    To copy to clipboard, switch view to plain text mode 
    And if I have a dialog included to my file called Dialog, so the OtherDialog will the replaced by Dialog? And what about "dlg"? and must on_aboutAction_triggered() be defined in slots section? I mean the same way that I do it with other functions?
    Last edited by Salazaar; 18th May 2007 at 21:58.

  6. #66
    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
    And if I have a dialog included to my file called Dialog, so the OtherDialog will the replaced by Dialog?
    Yes, you have to replace it with the name of a class you want to use.

    Quote Originally Posted by Salazaar View Post
    And what about "dlg"?
    It doesn't matter, it's just a variable.

    Quote Originally Posted by Salazaar View Post
    and must on_aboutAction_triggered() be defined in slots section?
    Yes, it has to be a slot.

    As a homework, please, get a copy of C++ Primer (Polish edition is called Podstawy języka C++) by S. Lippman and J. Lajoie and read parts 2--5.

  7. #67
    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 to connect dialog to a slot, I have to do this, what is described in posts #65, 66
    and also include this ui_about.h dialog file and nothing else? Will it be done correctly?

  8. #68
    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

    You don't connect a dialog to a slot. You connect a signal triggered() of the action actionAbout to a slot that has code which creates the dialog object and calls exec() on it to show it as modal.

  9. #69
    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

    Your absolutely right.
    Last edited by Salazaar; 20th May 2007 at 18:56.

  10. #70
    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

    There's a problem. I have those files:
    Maker.cpp
    Qt Code:
    1. #include <QtGui>
    2.  
    3. #include "maker.h"
    4.  
    5. MainWindow::MainWindow(QMainWindow *parent)
    6. : QMainWindow(parent)
    7. {
    8. ui.setupUi(this);
    9.  
    10. }
    11.  
    12. void MainWindow::on_actionAbout_triggered()
    13. {
    14.  
    15.  
    16. Dialog dlg( this );
    17.  
    18.  
    19.  
    20. dlg.exec();
    21.  
    22.  
    23.  
    24. }
    To copy to clipboard, switch view to plain text mode 
    Maker.h
    Qt Code:
    1. #ifndef MAKER_H
    2. #define MAKER_H
    3.  
    4. #include "ui_maker.h"
    5. #include "ui_about.h"
    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 
    ui_about.h
    Qt Code:
    1. #ifndef UI_ABOUT_H
    2. #define UI_ABOUT_H
    3.  
    4. #include <QtCore/QVariant>
    5. #include <QtGui/QAction>
    6. #include <QtGui/QApplication>
    7. #include <QtGui/QButtonGroup>
    8. #include <QtGui/QDialog>
    9. #include <QtGui/QLabel>
    10. #include <QtGui/QPushButton>
    11.  
    12. class Ui_Dialog
    13. {
    14. public:
    15. QLabel *label;
    16. QLabel *label_2;
    17. QLabel *label_3;
    18. QPushButton *pushButton;
    19.  
    20. void setupUi(QDialog *Dialog)
    21. {
    22. Dialog->setObjectName(QString::fromUtf8("Dialog"));
    23. label = new QLabel(Dialog);
    24. label->setObjectName(QString::fromUtf8("label"));
    25. label->setGeometry(QRect(15, 23, 361, 16));
    26. label->setLayoutDirection(Qt::LeftToRight);
    27. label->setTextFormat(Qt::AutoText);
    28. label_2 = new QLabel(Dialog);
    29. label_2->setObjectName(QString::fromUtf8("label_2"));
    30. label_2->setGeometry(QRect(15, 50, 351, 81));
    31. label_2->setLineWidth(1);
    32. label_2->setMidLineWidth(0);
    33. label_2->setTextFormat(Qt::RichText);
    34. label_2->setAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop);
    35. label_2->setWordWrap(true);
    36. label_3 = new QLabel(Dialog);
    37. label_3->setObjectName(QString::fromUtf8("label_3"));
    38. label_3->setGeometry(QRect(25, 163, 171, 21));
    39. pushButton = new QPushButton(Dialog);
    40. pushButton->setObjectName(QString::fromUtf8("pushButton"));
    41. pushButton->setGeometry(QRect(260, 250, 75, 23));
    42. pushButton->setDefault(true);
    43. pushButton->setFlat(false);
    44.  
    45. retranslateUi(Dialog);
    46.  
    47. QSize size(400, 293);
    48. size = size.expandedTo(Dialog->minimumSizeHint());
    49. Dialog->resize(size);
    50.  
    51. QObject::connect(pushButton, SIGNAL(clicked()), Dialog, SLOT(close()));
    52.  
    53. QMetaObject::connectSlotsByName(Dialog);
    54. } // setupUi
    55.  
    56. void retranslateUi(QDialog *Dialog)
    57. {
    58. Dialog->setWindowTitle(QApplication::translate("Dialog", "About", 0, QApplication::UnicodeUTF8));
    59. Dialog->setAccessibleName(QApplication::translate("Dialog", "About", 0, QApplication::UnicodeUTF8));
    60. label->setText(QApplication::translate("Dialog", "About TimeTable Maker", 0, QApplication::UnicodeUTF8));
    61. label_2->setText(QApplication::translate("Dialog", "...", 0, QApplication::UnicodeUTF8));
    62. label_3->setText(QApplication::translate("Dialog", "Thank you for using TimeTable Maker", 0, QApplication::UnicodeUTF8));
    63. pushButton->setText(QApplication::translate("Dialog", "OK", 0, QApplication::UnicodeUTF8));
    64. Q_UNUSED(Dialog);
    65. } // retranslateUi
    66.  
    67. };
    68.  
    69. namespace Ui {
    70. class Dialog: public Ui_Dialog {};
    71. } // namespace Ui
    72.  
    73. #endif // UI_ABOUT_H
    To copy to clipboard, switch view to plain text mode 
    And if I try to compile it, there appear errors:
    maker.cpp - in member function 'void MainWindow:: on_actionAbout_triggered()':
    maker.cpp:line 16: Dialog undeclared (first use)
    maker.cpp:line 16: Each undeclared identifier is reported only once for each function it appears in
    maker.cpp:line 16: Expected ; before 'dlg'
    maker.cpp:line 20: 'dlg' undeclared (first use)

    What's wrong? I've done everything how you'd described!
    Last edited by jacek; 21st May 2007 at 03:09. Reason: shortened too long line

  11. #71
    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

    Do you have a class called "OtherDialog"?

  12. #72
    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 wysota View Post
    Do you have a class called "OtherDialog"?
    No, I don't have a class called OtherDialog and also don't have class called Dialog (btw. my dialog is called Dialog) How (and where) do I have to create this class? Look at the code I'd posted above. Regards

  13. #73
    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 if you don't have such classes, why are you using them? You have to create a subclass of QDialog that uses your uic generated code to initialise itself which is explained in the link you're constantly being pointed to.

    Please, understand, there is nothing magical going on here. If you don't implement a class, you can't use it - it won't be created out of thin air. I asked you about your C++ knowledge and I was given an empty answer, but from what I see you don't know much about it. So I repeat Jacek's suggestion to take a good book about C++, be it either C++ Primer, Thinking in C++ (available online) or even Symfonia C++.

    The problem here is that if we don't give you exact code you are to copy and paste into your files, there is no way you're going to obtain the result you want, because you don't seem to try to do anything by yourself. It seems that you know what to do, because you implemented the exact same thing that is required here with the main window. I just can't seem to understand why don't you repeat the exact same approach with the dialog.
    We're all trying to teach you something here, but it seems we're doing something wrong, so please explain us what exactly you don't know how to do and I'm speaking of some fundamental things - like subclassing, creating variables, single or multiple inheritance, etc. Is this all known to you? Do you have any trouble handling those basics?

  14. #74
    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 wysota View Post
    Do you have any trouble handling those basics?
    A bit. Do I have to subclass this Dialog in the same way I was subclassing MainWindow?

  15. #75
    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
    A bit.
    Great, now we're getting somewhere. Please, if at any time you don't understand what we say (any term, code, etc.) just say so and we'll explain it.

    Do I have to subclass this Dialog in the same way I was subclassing MainWindow?
    Yes. This is exactly the same situation - you have a UI definition in one class and you want to apply it to a widget class (like QDialog or QMainWindow).

  16. #76
    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 wysota View Post
    Great, now we're getting somewhere. Please, if at any time you don't understand what we say (any term, code, etc.) just say so and we'll explain it.
    Thanks

    And can I subclass dialog in the same file I was subclassing MainWindow (maker.h, and include ui_about.h, ui_maker.h) ?

  17. #77
    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, but I suggest you use separate pair of files for that. You'll get cleaner code and faster compilation.

  18. #78
    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

    But in this case (subclassing QDialog) I don't define slots, do I?

  19. #79
    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

    Do you need any?

  20. #80
    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 suppouse no, because I'd defined all importand slots when I was subclassing MainWindow

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.