[Qt-interest] Basic signals between classes question

Phil phillor at telstra.com
Tue Jul 6 09:44:23 CEST 2010


Thank you for reading this.

This is another of those unresolved problems that I have never been able to 
solve although I have found a work around in the past, but not this time.

I have a main window and a dialog box that contains a line edit box. I'm
trying to pass the contents of the line edit box back to the main window, the 
parent.

A signal / slot mechanism like this seems be the logical option but "parent" 
is null for some reason. There must be a simple way around this.

connect(m_ui->elevationLineEdit, SIGNAL(textChanged(QString)), parent, 
SLOT(updateParkElevationSlot(QString)));

The main class looks like this:

Pest::Pest (QWidget* parent, Qt::WFlags fl)
                : QMainWindow (parent, fl), Ui::MainWindow(),
                    m_workerThread(new PollingThread(this))

Another method tried was to use a signal / slot connection within the dialog 
class itself to read the edit box and then have a main class function retrieve 
the variable el (as a reference) as follows:
 
void Pest::showRotatorDlg()
{
    QString el;

    if(rotatorDlg->showDialog())
       rotatorDlg->getParkAngels(el);
}

The slot does retrieve the contents of the edit box but it seems that after 
the OK button on the dialog box is pressed that a new instance of the 
rotatorDlg class is created and so el then contains "".

I have read through the documentation and many of the examples but I 
cannot see a solution to this problem.

As always, any help offered will be greatly appreciated.

-- 
Regards,
Phil



More information about the Qt-interest-old mailing list