[Qt-interest] Runtime Error :- connect: No such slot ...
Wm. G. Urquhart
wgu at wurquhart.co.uk
Fri Feb 19 12:13:59 CET 2010
Sean Harmer wrote:
> Hi,
>
> On Thursday 18 February 2010 20:47:07 Wm. G. Urquhart wrote:
>> Hi All,
>>
>> I have a class derived from QThread that contains some signals, but when
>> I try to connect these signals to the UI I get a runtime error telling
>> me that the SLOT to which I want to connect said signals to does not exist.
>>
>> In the UI header file I have
>>
>> private slots:
>> void loadComplete(size_t) ;
>>
>> and in the UI .cpp I have :
>>
>> void MyApp::loadComplete(size_t count)
>> {
>> ui->statusBar->showMessage(tr("Loaded %1 rows. Done.").arg(count), 5000)
> ;
>> }
>>
>> And this is the line I use to try to connect:
>>
>> connect(sqlLoader, SIGNAL(loadEnded(size_t)), this,
>> SLOT(loadComplete(size_t))) ;
>>
>> Both of the applicable headers are MOC processed and both contain the
>> Q_OBJECT macro, which leaves me seriously confused.
>>
>> Can anyone shed some light on this please?
>
> Probably yes, if you can provide a minimal compilable example that reproduces
> the problem. In doing so you may even spot the problem yourself.
Hi Sean,
Well needless to say I didn't find anything wrong when creating this
sample (is it that obvious?), so here it is.
This version uses a const QString & instead of an int but at runtime the
outcome is the same:
Object::connect: No such slot QPushButton::setText(const QString &) in
.\sigtest.cpp:9
Object::connect: (receiver name: 'pushButton')
So to replicate:
Signal Test Sample
sigtest.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SigTestClass</class>
<widget class="QDialog" name="SigTestClass">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>314</width>
<height>56</height>
</rect>
</property>
<property name="windowTitle">
<string>SigTest</string>
</property>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Thread</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_2">
<property name="geometry">
<rect>
<x>230</x>
<y>20</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Quit</string>
</property>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>
<include location="sigtest.qrc"/>
</resources>
<connections/>
</ui>
sigtest.h
#ifndef SIGTEST_H
#define SIGTEST_H
#include <QtGui/QDialog>
#include "ui_sigtest.h"
#include "SignalTest.h"
class SigTest : public QDialog
{
Q_OBJECT
public:
SigTest(QWidget *parent = 0, Qt::WFlags flags = 0);
~SigTest() { } ;
private:
Ui::SigTestClass ui;
SignalTest * pTest ;
};
#endif // SIGTEST_H
sigtest.cpp
SigTest::SigTest(QWidget *parent, Qt::WFlags flags) : QDialog(parent, flags)
{
ui.setupUi(this) ;
ui.pushButton_2->setDefault(true) ;
pTest = new SignalTest() ;
connect(ui.pushButton_2, SIGNAL(clicked()), this, SLOT(close())) ;
if (connect(pTest, SIGNAL(Boo(const QString &)), ui.pushButton,
SLOT(setText(const QString &))))
{
pTest->Start() ;
}
else
{
ui.pushButton->setText("Oops") ;
}
}
SignalTest.h
#ifndef _SIGNALTEST_H
#define _SIGNALTEST_H
#include <QObject>
#include <QThread>
class SignalTest : public QThread
{
Q_OBJECT
public:
SignalTest() ;
~SignalTest() { } ;
void Start() ;
signals:
void Boo(const QString &) ;
protected:
void run() ;
QString msg ;
} ;
#endif
SignalTest.cpp
#include "SignalTest.h"
SignalTest::SignalTest()
{
msg = "Done" ;
}
void SignalTest::Start()
{
start() ;
}
void SignalTest::run()
{
emit Boo(msg) ;
}
main.cpp
#include "sigtest.h"
#include <QtGui/QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
SigTest w;
w.show();
return a.exec();
}
More information about the Qt-interest-old
mailing list