[Qt-interest] Newbie question about setting a simple signal andslot with creator based code.

Tony Rietwyk tony.rietwyk at rightsoft.com.au
Wed Feb 18 00:03:46 CET 2009


Douglas wrote:

> /TryTwo/mainwindow.cpp:50: error: no matching function for call to
> 'MainWindow::connect(QSpinBox*&, const char [19],
> Ui::MainWindowClass*&, const char [24])'
> 
> This is my latest mystery. I know that I can make the connect commands
> in designer but I can't get it to work here, done by hand. I know what
> I have does not work and I have tried lots of others. What am I
> missing? It worked about like this is python. I even have the python
> code in remarks. Perhaps it is missing something in the header?
> 
> File mainwindow.cpp
> 
> MainWindow::MainWindow(QWidget *parent)
>     : QMainWindow(parent), ui(new Ui::MainWindowClass)
> {
> 
>     ui->setupUi(this);
>     QObject::connect(ui->spinBox_DX_2, SIGNAL(valueChanged(int)), ui,
> SLOT(label_DX_Cost_Set(int)));
> 
>     //QObject::connect(spinBox_ST_2, SIGNAL(valueChanged(int)),
> MainWindowClass, SLOT(STChangedSlot(int)));
> 
>     //connect(okButton, SIGNAL(clicked()), this, SLOT(checkValues()));
> 
> }

Hi Douglas, 

The generated ui class does not descend from QObject - hence the mismatch.
Putting the slots in it doesn't make sense either, since the file is
recreated when the ui is changed. The slots usually go on the QWidget
derived class (like MainWindow): 

    connect(ui->spinBox_DX_2, SIGNAL(valueChanged(int)), this,
SLOT(label_DX_Cost_Set(int)));

So the answer is in your okButton line! Make sure you understand about
'this' - I'm not sure what the Python equivalent is. 

C++ error messages are notoriously crytic. It can take a long time to get
used to them! 

Regards, 

Tony Rietwyk




More information about the Qt-interest-old mailing list