So the answer is no, you don't define slots :)
Printable View
So the answer is no, you don't define slots :)
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?
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.
So we define slots in private slots, and standard cpp functioms in private, right?
Yes, that's right.
And in maker.cpp I have to do the same what I was doing with MainWindow:
but without implementing slots, right?Code:
{ ui.setupUi(this); } void MainWindow::on_actionAbout_triggered() { Dialog dlg( this ); dlg.exec(); }
I have a problem. I've implemented this:
Maker.h
Code:
#ifndef MAKER_H #define MAKER_H #include "ui_maker.h" { Q_OBJECT public: private slots: void on_actionAbout_triggered(); private: Ui::MainWindow ui; }; #endif
About.h
Code:
#ifndef ABOUT_H #define ABOUT_H #include "ui_about.h" { Q_OBJECT public: private: Ui::Dialog ui; }; #endif
Maker.cpp
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); }
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::on_actionAbout_triggered()':
maker.cpp:17:error: no matching function for call to 'Dialog::Dialog(MainWindow* const)
about.h:9:note: candidates are Dialog::Dialog(const Dialog&)
about.h:13:note: Dialog::Dialog(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.
I replaced QDialog with QWidget but it didn't solve the problem:
maker.cpp:31:error: Prototype for Dialog::Dialog(QDialog*) does not match any in class Dialog
about.h:9:error: candidates are Dialog:Dialog(const Dialog&)
about:.h:13:error Dialog::Dialog(QWidget*)
What's wrong now? Regards
Most likely you forgot to change it in the .cpp file too.
Yes, now I changed it into cpp file too, but there appear error:
maker.cpp: In constructor Dialog::Dialog(QWidget*)
maker.cpp:31:error: Type 'class QWidget' is not a direct base of Dialog
What's wrong, now? Regards,
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. ;)
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
Do you know why it doesn't work?
Does class "Dialog" inherit QDialog?
Yes, I think so. Here are the files
Maker.h
Code:
#ifndef MAKER_H #define MAKER_H #include "ui_maker.h" { Q_OBJECT public: private slots: void on_actionAbout_triggered(); private: Ui::MainWindow ui; }; #endif
About.h
Code:
#ifndef ABOUT_H #define ABOUT_H #include "ui_about.h" { Q_OBJECT public: private: Ui::Dialog ui; }; #endif
Maker.cpp
And also main.cpp, ui_about.h, ui_maker.h which contents are obvious. So, what's wrong in it? RegardsCode:
#include <QtGui> #include "maker.h" #include "about.h" { ui.setupUi(this); } void MainWindow::on_actionAbout_triggered() { Dialog dlg( this ); dlg.exec(); } { ui.setupUi(this); }
The compiler told you what's wrong.
Dialog isn't derived directly from QWidget, so you can't invoke QWidget constructor, so this:
should be:
I've done it, but it didn't solve the problem. Compilation log:
http://allyoucanupload.webshots.com/...74960843080783
Regards