Signal And Slots
Hi,
I am trying to connect a combobox with a Qtreewidget.
I would like to answer if i could create my own slot (function) and connect it with the signal..
the code is this :
i would like to take the user choice from the combo kliniki through the slot fill,
but somewhere i always do something wrong!
I need some help.
thanks
Edit (Andre [developer.qt.nokia.com]): Code tags. Please use them for formatting code.
10 replies
No the tree doesn’t have the slot fill()! i created it and the error was: Object::connect: No such slot QTreeWidget::fill(QString) in ..\..\ARXIKO\qxsrexample.cpp:185.
what can i do?
Also what the difference between this
and this
With the second line i can call the slot fill but i this that there is no connection between the combo and the tree.
Edit by Andre [developer.qt.nokia.com]: Again, please use code tags for code.
The difference between
and
is:
With the first statement you tell your program that the slot fill(QString) which is located in the tree-object has to be called if kliniki generates the signal activated(QString). Whereas the second line tells that the slot fill(QString) is located in the actual object where the connect statement is located.
So if you defined the slot-function within your own implementation of QTreeWidget use the first, otherwise if it is defined in the object that contains the connects the latter.
The difference between the two statements is obviously that in the first instance, you connect to whatever object tree is pointing to, while in the second statement you connect to the object you call this code from.
So, where did you write this fill code for the tree? Could you show the relevant sections of your code?
Here is my code:
- void QXSRExample::addPersonsToUI()
- {
- while(!persons.isEmpty())
- {
- if (clinic2["clinical_department"] != clinic["clinical_department"])
- {
- kliniki->addItem(clinic2["clinical_department"]);
- clinic2=clinic;
- }
- }
- kliniki->addItem(clinic2["clinical_department"]);
- _layout->addWidget(kliniki);
- }
- {
- while(!persons2.isEmpty())
- {
- if (index==person["clinical_department"])
- {
- QStringList columns;
- columns << person["surname"] << person["name"] << person["birthdate"];
- tree->setColumnCount(3);
- tree->insertTopLevelItem(0, treeWidgetItem);
- }
- }
- _layout->addWidget(tree);
- }
What can i do?
EDIT: please use only one @-Tag before the complete code and one after…
Hi anatz,
- void QXSRExample::addPersonsToUI()
- {
- ...
- }
The signal of a combo box is: activated(const QString&). Have a look at the docs, the signature must be completely the same. So your slot also need to be fill(const QString&).
For future: please use the @-tags correctly: one in front of the first line of code and one after the last one. no doubles etc…
The signatures must be compatible. This implies not necessarily having the same signature than the signal:
- // having
- // void QComboBox::activated ( const QString & text ) [signal]
Only the connection to slotRef will fail, the other three are ok. So the code from annatz seems to be ok.
annatz, did you declare your slot fill() as a slot in your header file?
If you do not declare it as a slot like above the Qt system does not regard the method a such and the connection will eventually fail with the error message in your original post! You have to decide if the slot is public, protected or private, as in regular methods and class members.
Hi anatz, The signal of a combo box is: activated(const QString&). Have a look at the docs, the signature must be completely the same. So your slot also need to be fill(const QString&).
Actually, that is not quite true. Qt strips of the const and the & when connecting the two anyway. Also, the slot is allowed to have less parameters than the signal. These will be disgarded.
Then, on the code:
What I don’t understand in the code is the construction of lots of new widgets when a choice in a combobox is made. Why do you do that? Why don’t you just set values on widgets you already have? It seems like a huge waste to create new widgets for every different choice you make in the combo box.
You must log in to post a reply. Not a member yet? Register here!


