Reputation: 701
Qt v4.8.0, VC2010 compiler
I have a QMainWindow
based class and I'm trying to send it signals involving QUuid
However, every time I run it I get the errors:
Object::connect: No such slot MainWindow::on_comp_connected(QUuid) in ..\..\src\mainwindow.cpp:143
Object::connect: (receiver name: 'MainWindow')
It's driving me potty as the slot definitely does exist (it's in the moc_)
class MainWindow : public QMainWindow
{
Q_OBJECT
// SNIP private typedefs
public:
MainWindow(QWidget *parent = 0, Qt::WFlags flags = 0);
~MainWindow();
// SNIP public methods
signals:
void testSendQuuid(const QUuid &qcid);
public slots:
void on_comp_connected(const QUuid &qcid);
private:
// SNIP private parts
QOpenAcnController *acnInt; // This is where the signal comes from
};
At the end of the MainWindow
constructor (the line 143 mentioned) I have:
connect(acnInt, SIGNAL(callback_comp_connected(QUuid)),
this, SLOT(on_comp_connected(QUuid)));
Given that the slot is definitely there in the moc_mainwindow.cpp (I checked, it's slot #1), what on earth could be stopping the connection happening?
If I try to connect the testSendQuuid(QUuid)
signal to the slot, I get no such signal and no such slot as well.
I cannot for the life of me figure out why Qt is denying the existence of a slot that is most definitely there!
Upvotes: 10
Views: 54457
Reputation: 129
I solved the problem like this
private slots:
void on_comp_connected(const QUuid &qcid);
then in constructor
connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(on_comp_connected(QUuid)));
Upvotes: 0
Reputation: 1542
You need
connect(acnInt, SIGNAL(callback_comp_connected(QUuid)), this, SLOT(on_comp_connected(const QUuid&)));
Pass by value shouldn't match pass a const reference.
But I tried it and it does. I created a minimal project with QtCreator 2.4.1 using Qt 4.7.4 on Windows. I added a single label to the main window and modified MainWindow.cpp as follows
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(
this, SIGNAL(testSendQuuid(QUuid)),
this, SLOT(on_comp_connected(QUuid))
);
QUuid x = QUuid::createUuid();
emit testSendQuuid(x);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_comp_connected(const QUuid &qcid)
{
ui->label->setText(qcid.toString());
}
And I get a uuid on my main window.
I also tried with the two QUuid arguments in the connect changed to const QUuid& and that worked too.
So your problem must be build related.
Upvotes: 0
Reputation: 3094
Check whether whether that moc_mainwindow.cpp
is in your Build Path
. Or you are using some other moc_window.cpp file. Because, for ex: In QtCreator, it build the source to a new build directory. And also it uses old moc_cpp file(s) if you try to open the source in a different location.
What I am trying to say is the moc file which you checked may contain those slot definition, but compiler might be using some other moc file which was created earlier.
Upvotes: 8