[Qt-interest] Dialog box and signal/slot question

John McClurkin jwm at nei.nih.gov
Mon Nov 9 13:56:42 CET 2009


Phil wrote:
> Thank you for reading this.
> 
> I've moved on somewhat from my previous question and now I'm stuck with 
> a signal/slot connection.
> 
> This is how I add items to a table shown on a dialog:
> 
> void Configuration::showDialog(QString str)
> {
>   Configuration configDlg;
> 
>   for(int col = 0; col < 4; col++)
>   {
>     QTableWidgetItem *item = new QTableWidgetItem(list[col +1]);
>     item->setTextAlignment(Qt::AlignHCenter);
>     configDlg.freqTableWidget->setItem(row, col, item);
>   }
> 
> I now want to access a particular row in the table so I've added the following 
> line to my Configuration constructor:
> 
> connect(freqTableWidget, SIGNAL(cellActivated(int, int)), this, 
> SLOT(selectRow(int, int)));
> 
> The problem is that activating a cell does not connect to the selectRow slot.
> 
> It seems to me that I need to add "configDlg" to the connect code. But 
> configDlg is declared in the showDialog function and is not known to the 
> constructor.
> 
> I've tried adding "Configuration configDlg" as a private attribute in the 
> Configuration header file and I've tried a pointer as well and new in the 
> constructor. None of these methods are correct.
> 
> The addressbook example is close to what I'm trying to achieve but it's a 
> little complex and I cannot relate it to my particular case.
> 
> By the way, the Configuration class is not the main window.
> 
The code snippet you show doesn't make a lot of sense. Your showDialog 
function is a member of the Configuration class and inside that you are 
creating another Configuration class? Also, how does your connect 
statement relate to the Configuration class?



More information about the Qt-interest-old mailing list