Connecting slots dynamically
-
Hi!
I am quite new with QT and I'm kind of confused on how to program the following in QT designer:
I have a push button "Search" which activates a custom slot which performs a searching procedure in a database called SlotSearch(). Now the results of the search need to be shown on my GUI. So far the searching procedure is working correctly and I get my results.
However, it is a lot of information to display on the GUI. Basically the results consist of a number of records each containing specific information. Right now the resulting records are displayed in a table (within the SlotSearch()) and a specific record can be selected. Now I would like to connect the signal of this record selection using currentCellChanged(int,int,int,int) to a slot which loads the specific information within the record. I created a vector containing QWidgets called fielddata[i] within SlotSearch() where i is the row index of the selected record and now I need to show the one which is activated.
I'm confused on how to make this connection. I added:
@
QObject::connect(ui.tableWidget , SIGNAL ( currentCellChanged(int, int, int, int) ) , this, SLOT ( SlotSelectRecord (int, int, int, int) ) );
@
and:
@
void ANDS_GUI::SlotSelectRecord(int newrow, int newcol, int prevrow, int prevcol)
{
fielddata[newrow]->show();
}
@but this doesn't work because the variables are unknown. Maybe it's obvious, but I don't know how to get it done, any ideas?
Edit: please use code tags around code sections for readability; Andre
-
Where do you get that error? In the connection code, or in the slot?
You will need to make the connection in a location where you have access to both objects that need to be connected. In your slot, you obviously need access to your fielddata variable.However, it seems to be your design is not very scalable. Creating an array of widgets that you show on request is something that works if the number of widgets is fairly small. You'll run into performance issues once the numbers start to get higher.
It would be way more efficient to use the same widget for displaying the data, and just setting their values to match the data you want to show.
-
Thanks for your reply!
I don't think this is the best solution with the array of widgets indeed. Right now I have to different slots responding to different signals.
One slot which performs the search and orders the information when the search button is clicked.
The other slot is activated when the current cell is changed, but it needs information from the former slot which it does not receive since the first slot doesn't sent any output to it.I think about merging it to one slot and using the signal mapper to connect it to both signals. Still trying to figure it out!