Solved connect fails with QToolbar with QactionGroup/QActions/QMenu
-
Hi,
developing my first Qt App (Qt 5.15.2) on Linux (and btw trying to learn C++ so pretty sure my code is more nuts than sane)
My App connects to one or more databases showing the open connections in a toolbar in the QMainWindow.
I chose to put a QActionGroup in the toolbar containing the open connections as QActions since there must only be one connection selected at any time. The connections contain a QMenu with some QActions like Close, Reconnect, etc.
This all works, but now i'm struggling to connect the QMenu Actions to my QMainWindow because the compiler complains:In file included from /media/gweber/Data1/develop/stuff/koraq/src/main/koraq.cpp:1: In file included from /media/gweber/Data1/software/Qt/5.15.2/gcc_64/include/QtWidgets/QtWidgets:3: In file included from /media/gweber/Data1/software/Qt/5.15.2/gcc_64/include/QtWidgets/QtWidgetsDepends:3: In file included from /media/gweber/Data1/software/Qt/5.15.2/gcc_64/include/QtCore/QtCore:6: In file included from /media/gweber/Data1/software/Qt/5.15.2/gcc_64/include/QtCore/qabstractanimation.h:43: /media/gweber/Data1/software/Qt/5.15.2/gcc_64/include/QtCore/qobject.h:255:9: error: static_assert failed due to requirement 'bool((QtPrivate::CheckCompatibleArguments<QtPrivate::List<bool>, QtPrivate::List<QAction *>>::value))' "Signal and slot arguments are not compatible." Q_STATIC_ASSERT_X((QtPrivate::CheckCompatibleArguments<typename SignalType::Arguments, typename SlotType::Arguments>::value), ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /media/gweber/Data1/software/Qt/5.15.2/gcc_64/include/QtCore/qglobal.h:121:49: note: expanded from macro 'Q_STATIC_ASSERT_X' # define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message) ^ ~~~~~~~~~~~~~~~ /media/gweber/Data1/develop/stuff/koraq/src/main/koraq.cpp:108:9: note: in instantiation of function template specialization 'QObject::connect<void (QAction::*)(bool), void (Koraq::*)(QAction *)>' requested here connect(_close_connection, &QAction::triggered, this, &Koraq::connection_close); ^ In file included from /media/gweber/Data1/develop/stuff/koraq/src/main/koraq.cpp:1: In file included from /media/gweber/Data1/software/Qt/5.15.2/gcc_64/include/QtWidgets/QtWidgets:3: In file included from /media/gweber/Data1/software/Qt/5.15.2/gcc_64/include/QtWidgets/QtWidgetsDepends:3: In file included from /media/gweber/Data1/software/Qt/5.15.2/gcc_64/include/QtCore/QtCore:6: In file included from /media/gweber/Data1/software/Qt/5.15.2/gcc_64/include/QtCore/qabstractanimation.h:43: In file included from /media/gweber/Data1/software/Qt/5.15.2/gcc_64/include/QtCore/qobject.h:46: In file included from /media/gweber/Data1/software/Qt/5.15.2/gcc_64/include/QtCore/qobjectdefs.h:50: /media/gweber/Data1/software/Qt/5.15.2/gcc_64/include/QtCore/qobjectdefs_impl.h:152:21: error: cannot initialize a parameter of type 'QAction *' with an lvalue of type 'typename RemoveRef<bool>::Type' (aka 'bool') (o->*f)((*reinterpret_cast<typename RemoveRef<SignalArgs>::Type *>(arg[II+1]))...), ApplyReturnValue<R>(arg[0]); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /media/gweber/Data1/software/Qt/5.15.2/gcc_64/include/QtCore/qobjectdefs_impl.h:185:91: note: in instantiation of member function 'QtPrivate::FunctorCall<QtPrivate::IndexesList<0>, QtPrivate::List<bool>, void, void (Koraq::*)(QAction *)>::call' requested here FunctorCall<typename Indexes<ArgumentCount>::Value, SignalArgs, R, Function>::call(f, o, arg); ^ /media/gweber/Data1/software/Qt/5.15.2/gcc_64/include/QtCore/qobjectdefs_impl.h:418:36: note: in instantiation of function template specialization 'QtPrivate::FunctionPointer<void (Koraq::*)(QAction *)>::call<QtPrivate::List<bool>, void>' requested here FuncType::template call<Args, R>(static_cast<QSlotObject*>(this_)->function, static_cast<typename FuncType::Object *>(r), a); ^ /media/gweber/Data1/software/Qt/5.15.2/gcc_64/include/QtCore/qobjectdefs_impl.h:427:57: note: in instantiation of member function 'QtPrivate::QSlotObject<void (Koraq::*)(QAction *), QtPrivate::List<bool>, void>::impl' requested here explicit QSlotObject(Func f) : QSlotObjectBase(&impl), function(f) {} ^ /media/gweber/Data1/software/Qt/5.15.2/gcc_64/include/QtCore/qobject.h:266:32: note: in instantiation of member function 'QtPrivate::QSlotObject<void (Koraq::*)(QAction *), QtPrivate::List<bool>, void>::QSlotObject' requested here new QtPrivate::QSlotObject<Func2, typename QtPrivate::List_Left<typename SignalType::Arguments, SlotType::ArgumentCount>::Value, ^ /media/gweber/Data1/develop/stuff/koraq/src/main/koraq.cpp:108:9: note: in instantiation of function template specialization 'QObject::connect<void (QAction::*)(bool), void (Koraq::*)(QAction *)>' requested here connect(_close_connection, &QAction::triggered, this, &Koraq::connection_close); ^ 2 errors generated.
the relevant code piece:
qDebug() << "update_connection_toolbar"; m_main_connection_toolbar->clear(); if (m_main_connection_toolbar_actiongroup != nullptr) { delete m_main_connection_toolbar_actiongroup; } m_main_connection_toolbar_actiongroup = new QActionGroup(this); for (auto &cp : connection_pool_registry::get_instance().get_connection_pools()) { qDebug() << "update_connection_toolbar: add " << cp->get_connect_string() << " , " << cp->get_connection_color(); QPixmap px(13,13); px.fill(QColor(cp->get_connection_color())); QIcon icon(px); QAction *_a = new QAction(cp->get_connect_string(), m_main_connection_toolbar_actiongroup); _a->setIcon(icon); _a->setCheckable(true); _a->setEnabled(true); _a->setChecked(true); //_a->setToolTip("test tooltip\nline2\nline3"); _a->setData(cp->get_connect_string()); m_main_connection_toolbar_actiongroup->addAction(_a); auto *_menu = new QMenu(m_main_connection_toolbar); auto *_close_connection = new QAction(tr("Close"), _menu); auto *_reconnect_connection = new QAction(tr("Reconnect"), _menu); _menu->addAction(_close_connection); _menu->addAction(_reconnect_connection); _a->setMenu(_menu); connect(_close_connection, &QAction::triggered, this, &Koraq::connection_close); <- fail } m_main_connection_toolbar->addActions(m_main_connection_toolbar_actiongroup->actions()); connect(this->m_main_connection_toolbar_actiongroup, &QActionGroup::triggered, m_con_pool_reg, &connection_pool_registry::on_click_actiongroup);
No matter what, i'm not able to connect the actions in this constellation - any ideas ?
thanks in advance & regards,
gerald -
What's the signature of Koraq::connection_close()?
/edit: According to the compiler output it is Koraq::connection_close(QAction*) but the signal triggerd() only has one bool parameter so it can't work.
-
@Christian-Ehrlicher
yes, signature was connection_close(QAction*), but i just realized that i have to connect to the _menu and not to _close_connection. Now its working as intended. Thanks :) -
@unficyp Then please mark the topic as solved, thx.