0

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 qDebugs 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?

Jacob Krieg
  • 2,834
  • 15
  • 68
  • 140
  • 1
    One thing I see is your are using Qt4 which does not support this type of connect() – drescherjm May 16 '15 at 13:52
  • 1
    ***My project builds fine if I build it from QtCreator but when I build it from command line I get a strange error.*** Possibly you are using Qt5 with QtCreator? – drescherjm May 16 '15 at 13:55

1 Answers1

0

Found the problem...I was building a Qt5.5 project with qmake version 4...

Jacob Krieg
  • 2,834
  • 15
  • 68
  • 140
  • 1
    Hmm. I guess I should have pushed refresh before I commented. For some reason I did not have this answer on my side.. – drescherjm May 16 '15 at 13:56