5
votes

I'm using Qt in Visual Studio 2013 in C++. I'm trying to connect a signal to a slot. The problem is that the signal is sent but the slot function is never called and I don't know what happened. This code was working earlier but after I migrated the code from Visual Studio 2012 in 32 bit to Visual Studio 2013 in 64 bit and made some changes, it doesn't work anymore. It prints the debug statements: before sending, image sent, and connected but it doesn't print out image received. Can someone please help?

Streamer.h

signals:
    //Signal to output frame to be displayed
    void processedImageStream(const vector<QImage> &imgs, const QImage &image2, const QImage &image3, const QImage &image4);

Streamer.cpp in the run() function

qDebug() << "before sending";
emit processedImageStream(imgs,imgIntel, imgIntelDepth, imgIntelIR);
qDebug() << "images sent!";

MainWindow.h

private slots:
    //Display video frame in streamer UI
    void updateStreamerUI(const vector<QImage> &imgs, const QImage &imgIntel, const QImage &imgIntelDepth, const QImage &imgIntelIR);
private:
    Streamer* myStreamer;

MainWindow.cpp

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
    //Streamer initialization
    myStreamer = new Streamer();
    QObject::connect(myStreamer, SIGNAL(processedImageStream(vector<QImage>, QImage, QImage, QImage)), this, SLOT(updateStreamerUI(vector<QImage>, QImage, QImage, QImage)));
    qDebug() << "connected";
    ui.setupUi(this);
}

//slot for when new images are sent from the Streamer class
void MainWindow::updateStreamerUI(const vector<QImage> &imgs, const QImage &imgIntel, const QImage &imgIntelDepth, const QImage &imgIntelIR) {
    qDebug() << "images received!";
    //rest of the code
}
2
What is the return value of QObject::connect()?JKSH
The return value is true so it must be connecteduser3838815

2 Answers

10
votes

I don't know if this is at the heart of your problem or not, but QVector already is ready for passing around in the Qt Meta Object system. Custom types need to be registered.

qRegisterMetaType<T>("T");

Standard vector, and standard library collections may be exempt... I haven't used them lately.

Qt's runtime connection of signals and slots prints out a warning to the application output when it can't perform the connection. You can also look at the return value from QObject::connect.

A side note, not directly related to the question, but I've had issues with QVector and storing local objects in it. If done improperly, the objects will go out of scope, and you will get weird errors when accessing it. Sometimes it will not happen until you run it in debug mode. If you initialize your objects on the heap, you don't have to worry about parts of it going out of scope, but you do need to clean up before calling clear on your collection.

Read up on QVector and give it a spin.

Also at the top of each of your slots, put the following:

qDebug() << Q_FUNC_INFO;
0
votes

Signal/Slot signatures must match EXACTLY. I have even had problems with using directives (e.g. using std::string;) with Qt in that it doesn't recognize a string as a std::string.

It also looks like the declaration for MainWindow::updateStreamerUI doesn't match the definition in the .cpp file.

For example, change the declaration of MainWindow::updateStreamerUI to this:

void updateStreamerUI(const vector<QImage> &imgs, const QImage &imgIntel, const QImage &imgIntelDepth, const QImage &imgIntelIR)

Then update the definition accordingly in MainWindow.cpp.

One more thing to try is to fully-qualify std::vector in both the signal AND the slot definitions AND declarations, e.g.

void processedImageStream(const std::vector<QImage> &imgs, const QImage &image2, const QImage &image3, const QImage &image4);

void updateStreamerUI(const std::vector<QImage> &imgs, const QImage &imgIntel, const QImage &imgIntelDepth, const QImage &imgIntelIR);