I have a big problem. I created a dummy project to isolate my error. Because is a project with 6 files and it is unfeasible to add all the code here I created a github project and added all the code there while describing the idea here. You can take a look at the code there.
Source code for main.cpp:
#include <QApplication>
#include <QObject>
#include "mainwindow.h"
#include "testclass.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
TestClass c;
QObject::connect(&w, &MainWindow::mySignal,
&c, &TestClass::mySlot);
w.show();
return a.exec();
}
Class MainWindow
has a Q_SIGNAL
which gets emitted when I press a button on the from and mySlot
is just a Q_SLOT
in TestClass
(which inherits QObject
) which qDebug
s a message.
My project builds fine if I build it from QtCreator
but when I build it from command line I get a strange error.
What I do from command line:
$ qmake QMAKE_TEST.pro
$ make
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -o main.o main.cpp
In file included from main.cpp:4:0:
mainwindow.h: In function ‘int main(int, char**)’:
mainwindow.h:19:7: error: ‘void MainWindow::mySignal()’ is protected
void mySignal();
^
main.cpp:14:36: error: within this context
QObject::connect(&w, &MainWindow::mySignal,
^
main.cpp:15:41: error: no matching function for call to ‘QObject::connect(MainWindow*, void (MainWindow::*)(), TestClass*, void (TestClass::*)())’
&c, &TestClass::mySlot);
^
main.cpp:15:41: note: candidates are:
In file included from /usr/include/qt4/QtCore/qcoreapplication.h:45:0,
from /usr/include/qt4/QtGui/qapplication.h:45,
from /usr/include/qt4/QtGui/QApplication:1,
from main.cpp:1:
/usr/include/qt4/QtCore/qobject.h:204:17: note: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
static bool connect(const QObject *sender, const char *signal,
^
/usr/include/qt4/QtCore/qobject.h:204:17: note: no known conversion for argument 2 from ‘void (MainWindow::*)()’ to ‘const char*’
/usr/include/qt4/QtCore/qobject.h:217:17: note: static bool QObject::connect(const QObject*, const QMetaMethod&, const QObject*, const QMetaMethod&, Qt::ConnectionType)
static bool connect(const QObject *sender, const QMetaMethod &signal,
^
/usr/include/qt4/QtCore/qobject.h:217:17: note: no known conversion for argument 2 from ‘void (MainWindow::*)()’ to ‘const QMetaMethod&’
/usr/include/qt4/QtCore/qobject.h:337:13: note: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
inline bool QObject::connect(const QObject *asender, const char *asignal,
^
/usr/include/qt4/QtCore/qobject.h:337:13: note: no known conversion for argument 2 from ‘void (MainWindow::*)()’ to ‘const char*’
make: *** [main.o] Error 1
$
$
First of all why does it say that mySignal
si protected
because AFAIK all Q_SIGNALS
are public? Secondly why this works perfectly if I run it from Qt Creator
and I get errors when I run it from command line?
Can anybody help me please?