I want to connect action in my menu called actionAbout to dialog which is in ui_about
Printable View
I want to connect action in my menu called actionAbout to dialog which is in ui_about
if a ucer clicks a button, than about dialog is displayed
Right
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?Code:
void MainWindow::on_actionAbout_triggered() { OtherDialog dlg( this ); dlg.exec(); }
Yes, you have to replace it with the name of a class you want to use.
It doesn't matter, it's just a variable.
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.
;) 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?
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.
Your absolutely right.
There's a problem. I have those files:
Maker.cpp
Maker.hCode:
#include <QtGui> #include "maker.h" { ui.setupUi(this); } void MainWindow::on_actionAbout_triggered() { Dialog dlg( this ); dlg.exec(); }
ui_about.hCode:
#ifndef MAKER_H #define MAKER_H #include "ui_maker.h" #include "ui_about.h" { Q_OBJECT public: private slots: void on_actionAbout_triggered(); private: Ui::MainWindow ui; }; #endif
And if I try to compile it, there appear errors:Code:
#ifndef UI_ABOUT_H #define UI_ABOUT_H #include <QtCore/QVariant> #include <QtGui/QAction> #include <QtGui/QApplication> #include <QtGui/QButtonGroup> #include <QtGui/QDialog> #include <QtGui/QLabel> #include <QtGui/QPushButton> class Ui_Dialog { public: QLabel *label; QLabel *label_2; QLabel *label_3; QPushButton *pushButton; { label->setLayoutDirection(Qt::LeftToRight); label->setTextFormat(Qt::AutoText); label_2->setLineWidth(1); label_2->setMidLineWidth(0); label_2->setTextFormat(Qt::RichText); label_2->setAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop); label_2->setWordWrap(true); pushButton->setDefault(true); pushButton->setFlat(false); retranslateUi(Dialog); size = size.expandedTo(Dialog->minimumSizeHint()); Dialog->resize(size); } // setupUi { Dialog->setAccessibleName(QApplication::translate("Dialog", "About", 0, QApplication::UnicodeUTF8)); label->setText(QApplication::translate("Dialog", "About TimeTable Maker", 0, QApplication::UnicodeUTF8)); label_3->setText(QApplication::translate("Dialog", "Thank you for using TimeTable Maker", 0, QApplication::UnicodeUTF8)); Q_UNUSED(Dialog); } // retranslateUi }; namespace Ui { class Dialog: public Ui_Dialog {}; } // namespace Ui #endif // UI_ABOUT_H
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!:(
Do you have a class called "OtherDialog"?
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?
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.
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).Quote:
Do I have to subclass this Dialog in the same way I was subclassing MainWindow?
Yes, but I suggest you use separate pair of files for that. You'll get cleaner code and faster compilation.
But in this case (subclassing QDialog) I don't define slots, do I?
Do you need any?
I suppouse no, because I'd defined all importand slots when I was subclassing MainWindow