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).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
So the answer is no, you don't define slots![]()
ThanksAnd 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?
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
And in maker.cpp I have to do the same what I was doing with MainWindow:
but without implementing slots, right?Qt Code:
{ ui.setupUi(this); } void MainWindow::on_actionAbout_triggered() { Dialog dlg( this ); dlg.exec(); }To copy to clipboard, switch view to plain text mode
I have a problem. I've implemented this:
Maker.h
Qt Code:
#ifndef MAKER_H #define MAKER_H #include "ui_maker.h" { Q_OBJECT public: private slots: void on_actionAbout_triggered(); private: Ui::MainWindow ui; }; #endifTo copy to clipboard, switch view to plain text mode
About.h
Qt Code:
#ifndef ABOUT_H #define ABOUT_H #include "ui_about.h" { Q_OBJECT public: private: Ui::Dialog ui; }; #endifTo copy to clipboard, switch view to plain text mode
Maker.cpp
Qt Code:
#include <QtGui> #include "maker.h" #include "about.h" { ui.setupUi(this); } void MainWindow::on_actionAbout_triggered() { Dialog dlg( this ); dlg.exec(); } { ui.setupUi(this); }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
It should be:
The dialog of yours demands a QDialog as a parent. QMainWindow is not a QDialog but both are QWidgets.Qt Code:
class Dialog ... { ... ... };To copy to clipboard, switch view to plain text mode
J-P Nurmi
Bookmarks