6

I try to become more familiar with singnals and slots with Qt. I want to emit a signal in one class and want to handle it at one other. Here my example code:

main.c

#include "mainwindow.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); } 

mainwindow.h

#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> class Emiter { signals: void anSignal (); }; class MainWindow : public QMainWindow { Q_OBJECT private slots: void handleEmitter (); public: MainWindow(QWidget *parent = 0); }; #endif // MAINWINDOW_H 

mainwindow.cpp

#include "mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { auto emiter = new Emiter(); connect( emiter, &Emiter::anSignal, this, &MainWindow::handleEmitter ); } void MainWindow::handleEmitter() { } 

Then I get this error:

error: ‘qt_metacall’ is not a member of ‘Emiter’ enum { Value = sizeof(test(&Object::qt_metacall)) == sizeof(int) }; 

What does this mean?

0

2 Answers 2

7

Signals and slots are available only in QObject derived classes, and a Q_OBJECT macro is needed.

class Emiter : public QObject { Q_OBJECT public: signals: void anSignal (); }; 

For more detail answer: click here

Sign up to request clarification or add additional context in comments.

Comments

7

Another case is if you use multiple inheritances, you need to put QObject as the first parent class.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.