hello guys i need a small help how do i connect().In QT designer we add a slots in .ui file but when we are using IDE's(code blocks) how do i define a slot?
thank you
hello guys i need a small help how do i connect().In QT designer we add a slots in .ui file but when we are using IDE's(code blocks) how do i define a slot?
thank you
If I understand your question correctly, look at your generated ui.mainwindow.h file and you will see.
You want to ask: how you define slots from code? In this case the answer is: just like a regular function (only that it have public slots: "access specifier") and it usually returns void (it can have a return value, but it is ignored when the slot is called from connection with signal, it can be used only if you call the slot like any other member function of your class)
so i guess my code should be
Qt Code:
public slots: void my_slot() { /* some code here */ } int main(int argc, char* argv[]) { quit.show(); return app.exec(); }To copy to clipboard, switch view to plain text mode
am i right.
and i am extremely sorry for not express my question properly.
No, that code it's not working
The way if you really need to "add" a slot to the QApplication object is: create a class that derives from QApplication and declare the public slots in the .h file of the class, and define them in .cpp
But: I don't think you need that (at least not right now)
I think you need to connect your clicked() signal of the button to a already existing slot of your application, like this:
Qt Code:
#include <QApplication> #include <QtGui> int main(int argc, char* argv[]) { &app,SLOT(quit())); // connect to already existing slot quit() of your QApplication object (meaning app) quit.show(); return app.exec(); }To copy to clipboard, switch view to plain text mode
LE: i didn't said "politically correct" in the previous post, so:
this: "Slots are just like functions"
should be: "Slots are just like member functions (of some class)"
I'm pretty sure that you don't want or need to subclass the QApplication, so tell us with more details what you want (like what widgets do you have, etc...) So we can give you a better advice.
Most likely you will need to just use signals and slots to connect your widgets and update values
LE:
Also post the code that doesn't do what you want (or some example with the same issue)
And for creating your own class by inherit from another, you need a little experience with c++, so you will need to do some tutorials or better read a book (maybe a c++ book first if you are not comfortable with it)
Last edited by Zlatomir; 6th July 2010 at 16:30.
Bookmarks