signal slots question
hi everybody . i have one question
- #include <QtGui>
- void slt()
- {
- // do something
- }
- int main(int argc, char *argv[])
- {
- QPushButton btn;
- // connect btn signal(clicked()) to slt "function" !! i want connect to function not object!
- return app.exec();
- }
tnx for your help :)
6 replies
What you need is some basic knowledge of Qt. And this will be useful for you www.catb.org/~esr/faqs/smart-questions.html
————————
What you provided are some Qt4’s code snippets, but your slt() is not a Qt SLOT at all!
However, you can do similar thing with Qt5 using the new SIGNAL & SLOT syntax.
Read the manual carefully.
I think what you need is to:
- learn better English
- get some more practice in object oriented programming
- rethink and rephrase your questions so that other people – who want to help you – can understand them clearly
- read Qt documentation on signal and slot mechanism [qt-project.org], it’s really well written.
The answer to your questions, as far as I can get what you mean, is this: you can declare multiple slots in a single class, and connect your button signals to them (that is more or less the standard practice), or create one slot and handle all signals there (this is ugly, I won’t recommend).
About “how can I declare this”… really, really, DO read the docs. Here is a snippet:
- public slots:
- void mySlot();
And in source somewhere:
- connect(someButton, SIGNAL(clicked()), someObject, SLOT(mySlot()));
- .....
- void MyClass::mySlot() {
- /// code
- }
You must log in to post a reply. Not a member yet? Register here!





