So the answer is no, you don't define slots![]()
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
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?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
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
Most likely you forgot to change it in the .cpp file too.
J-P Nurmi
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,
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
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
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
And also main.cpp, ui_about.h, ui_maker.h which contents are obvious. So, what's wrong in it? RegardsQt 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
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:
{ ...To copy to clipboard, switch view to plain text mode
should be:
Qt Code:
{ ...To copy to clipboard, switch view to plain text mode
I've done it, but it didn't solve the problem. Compilation log:
http://allyoucanupload.webshots.com/...74960843080783
Regards
Bookmarks