I'm stuck at this.
I want to connect a slot, dialogAccepted(); , to a QDialogButtonBox "buttonBox" ,accepted() signal. My slot is in the class Widget and the signal comes from class Dialog(which is a public QDialog).
widget.cpp:
Printable View
I'm stuck at this.
I want to connect a slot, dialogAccepted(); , to a QDialogButtonBox "buttonBox" ,accepted() signal. My slot is in the class Widget and the signal comes from class Dialog(which is a public QDialog).
widget.cpp:
Connect your signal before you show your dialog:
Code:
connect(dialog1, SIGNAL(whatever), this, SLOT(yourSlot)); dialog1->show();
Well I get the following error:
This is the connect line:Code:
F:/Documents/QT Projects/ANClock/widget.cpp:21: error: no matching function for call to `Widget::connect(Dialog&, const char*, Widget* const, const char*)'
Code:
connect(dialog, SIGNAL(accepted()), this, SLOT(tempUsage()));
try
&dialog
Actually it looks like you put variable names in connect while you should connect only prototypes. Something like:
Code:
{ Q_OBJECT public: ~myCustomWidget1(); signal: drawMyPicture(int x, int y, const QPicture& pict); }; { Q_OBJECT public: ~myCustomWidget2(); public slots: void drawSomething(int x, int y, const QPicture& pict); }; // Somewhere in your code ... myCustomWidget1* widget1 = new myCustomWidget1(this); myCustomWidget2* widget2 = new myCustomWidget2(this); connect(widget1, SIGNAL(drawMyPicture(int, int, const QPicture&)), widget2, SLOT(drawSomething(int, int, const QPicture&)));
Hope that helps.
PS.
Code:
connect(classOne, SIGNAL(classOneSignal(int x)), classTwo, SLOT(classTwoSlot(int x)));
will not produce any error but will not work while this one
Code:
connect(classOne, SIGNAL(classOneSignal(int)), classTwo, SLOT(classTwoSlot(int)));
works fine.
And just notice that you close the namespace Ui. So your declaration is incorrect. It should be Also it is a bit strange declaration. Is it designer-made class?
I mean compile time error. Actually I do prefer to see compile time error instead of looking through the console. So you are half right. Run time error != build time error.Quote:
Actually, that WOULD produce an error, but at runtime when connect() is called, rather than compile time. You'll get an error stating that there's no such signal.
About dialog. Looks like you draw in designer, right? if so you need multiple inheritance where the first class is exactly the base class of your widget (QDialog, QScrollArea, etc) and second is your Ui based class.
Code:
// Login details dialog { Q_OBJECT public: ~LoginDetails(); } // And in the constructor of this class very urgent to keep the initialization sequence and don't forget to initialize Ui as well LoginDetails::LoginDetails( QWidget* parent, Qt::WindowFlags flags) { setupUi(this); // should go first!!! // Your init }
Hope that helps
I thought I clearly stated that in my post:
It was a "Just for your information". I know it's not a compile time error, but you might not have known about it and thought it was useful. Considering connect() takes a char *, it's impossible for it to know at compile time that a signal doesn't exist. You can put whatever you like for the signal and slot and it'll be happy at compile time.Quote:
Actually, that WOULD produce an error, but at runtime when connect() is called, rather than compile time. You'll get an error stating that there's no such signal.
This error says that there is no such 'connect' method? why? Because every connect needs pointers to an objects, not references or anything else. And as you see in your compile error:
the compiler is right in this case (as always) because it says you want to pass a reference to your dialog, not a pointer, and there is no suitable method.Quote:
Widget::connect(Dialog&, ...
So because you have in your header file:
You have to use C/C++ '&' operator to get the pointer (address):Code:
Dialog dialog;
Code:
connect(&dialog,...
You lost me here...:confused: Let me see if I understood right, I should use Multiple Inheritance instead of Single Inheritance? The code generated by QtCreator seems to be single inheritance, I never changed that, but is that necessary?
Yes I use the designer to create the forms..
Multiple Inheritance is generally a bad idea. You should use single inheritance unless you have a good reason. This way all your ui objects are behind the 'ui' object rather than exposed and polluting the same class as your implementation. Multiple inheritance also makes it more messy if another class includes your classes header file.
I read at QT archives that QT Creator uses single inheritance because that compiles much quicker and etc, etc ...
But there's this QT beginners tutorial that says multiple inheritance is the preferred way to write Qt applications.
Whatever.... So single inheritance is better?
Use whichever you prefer. I prefer single inheritance as it keep the ui private, but some prefer multiple so they can access the ui directly.