我在Kubuntu上使用Qt 5小部件构建了一个应用程序,在这个应用程序中,我用类StateMachine
中的一个函数连接了这个操作
QObject::connect(
ui->actionOpen, &QAction::triggered, &sm, &StateMachine::open_file);
很抱歉,我不能分享这里的所有代码,这是一个商业项目。
在Kubuntu上使用g++ 4.9可以很好地工作。我现在试着在openSUSE 13.1上编译它,它只有g++ 4.8,我在那里找不到Qt 5的头。因此,我尝试用QT4.8构建它,QT4.8在默认存储库中是可用的。然后我得到了这个错误:
/usr/include/QtGui/qaction.h: In constructor ‘MainWindow::MainWindow(QWidget*)’:
/usr/include/QtGui/qaction.h:228:10: error: ‘void QAction::triggered(bool)’ is protected
void triggered(bool checked = false);
^
/project/gui/mainwindow.cpp:26:35: error: within this context
ui->actionOpen, &QAction::triggered, &sm, &StateMachine::open_file);
^
/project/gui/mainwindow.cpp:26:75: error: no matching function for call to ‘MainWindow::connect(QAction*&, void (QAction::*)(bool), StateMachine*, void (StateMachine::*)())’
ui->actionOpen, &QAction::triggered, &sm, &StateMachine::open_file);
^
/project/gui/mainwindow.cpp:26:75: note: candidates are:
In file included from /usr/include/QtCore/QObject:1:0,
from /project/gui/AxisState.hpp:9,
from /project/gui/projectionview.h:7,
from /project/gui/mainwindow.h:5,
from /project/gui/mainwindow.cpp:3:
/usr/include/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/QtCore/qobject.h:204:17: note: no known conversion for argument 2 from ‘void (QAction::*)(bool)’ to ‘const char*’
/usr/include/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/QtCore/qobject.h:217:17: note: no known conversion for argument 2 from ‘void (QAction::*)(bool)’ to ‘const QMetaMethod&’
/usr/include/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/QtCore/qobject.h:337:13: note: no known conversion for argument 2 from ‘void (QAction::*)(bool)’ to ‘const char*’
In file included from /usr/include/QtGui/QAction:1:0,
from /project/gui/ui_mainwindow.h:13,
from /project/gui/mainwindow.cpp:5:
/usr/include/QtGui/qaction.h:228:10: error: ‘void QAction::triggered(bool)’ is protected
void triggered(bool checked = false);
^
我查看了QAction 4.8文档,看起来triggered(bool)
是一个公共信号。然后我查看了/usr/include/QtGui/qaction.h
文件,发现它如下所示:
protected:
bool event(QEvent *);
QAction(QActionPrivate &dd, QObject *parent);
public Q_SLOTS:
#ifdef QT3_SUPPORT
inline QT_MOC_COMPAT void setOn(bool b) { setChecked(b); }
#endif
void trigger() { activate(Trigger); }
void hover() { activate(Hover); }
void setChecked(bool);
void toggle();
void setEnabled(bool);
inline void setDisabled(bool b) { setEnabled(!b); }
void setVisible(bool);
Q_SIGNALS:
void changed();
void triggered(bool checked = false);
void hovered();
因此,它位于Q_SIGNALS
块中,它确实出现在protected
块下面,但是这些信号应该是公开的。
我怎样才能让这个程序编译?
发布于 2015-05-10 12:15:02
看上去就像在QT4.x中使用Qt5信号时隙连接语法一样。只需尝试使用QT4.x连接语法:
QObject::connect(ui->actionOpen, SIGNAL(triggered()), &sm, SLOT(open_file()));
https://stackoverflow.com/questions/30151127
复制相似问题