我有一个大问题。我创建了一个虚拟项目来隔离我的错误。 因为是一个包含6个文件的项目,并且在这里添加所有代码是不可行的,所以我创建了一个github project并在此处添加了所有代码,同时描述了这个想法。你可以看看那里的代码。
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();
}
类MainWindow
有一个Q_SIGNAL
,当我按下按钮上的按钮时会发出mySlot
Q_SLOT
只是TestClass
中的QObject
(继承qDebug
)QtCreator
消息。
如果我从$ 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
$
$
构建它,我的项目构建正常但是当我从命令行构建它时,我得到一个奇怪的错误。
我从命令行做什么:
mySignal
首先为什么说protected
si Q_SIGNALS
,因为AFAIK所有Qt Creator
都是公开的?其次,如果我从 function afterAjaxResponse(responseText) {
cache[ajaxIdentifier]=responseText;
}
运行它并且从命令行运行它时会出现错误,那么为什么这样可以正常工作?
有人可以帮帮我吗?
答案 0 :(得分:0)
发现问题...我正在使用Qt5.5
版本4构建qmake
项目......