Solved Debug output when calling QToolBar::addAction()
-
I'm getting a debug output message:
QObject::connect: Use the SLOT or SIGNAL macro to connect DEditStars::dragButtonPressed
when I do:
QToolBar t(&w); QIcon dragRect("C:/Users/amonra/Documents/GitHub/DSS/DeepSkyStacker/Buttons/ButtonSelect_Up.bmp"); t.setOrientation(Qt::Vertical); t.addAction(dragRect, "", &editor, "dragButtonPressed");
clearly Qt doesn't love me a lot, but why?
-
@Perdrix said in Debug output when calling QToolBar::addAction():
Just to be 100% clear, and get you on the right track of new syntax so you will like it(!), as @Pl45m4 has said the whole line needs to be:t.addAction(dragRect, "", &editor, &DEditStars::dragButtonPressed);
Page https://wiki.qt.io/New_Signal_Slot_Syntax gives you comparative examples.
-
because you didn't give it a slot, but a normal string...
-
Is
DEditStars
aQObject
? Do you haveQ_OBJECT
macro in this class? Is your functiondragButtonPressed
a slot?And dont put the function name in double quotes, like @Bonnie already said
-
Yes, yes and yes!
#include <QObject> class DEditStars : public QObject { Q_OBJECT typedef QObject Inherited; public: DEditStars() : QObject() { }; virtual ~DEditStars() {}; public slots: void mousePressEvent(QMouseEvent* e); void mouseMoveEvent(QMouseEvent* e); void mouseReleaseEvent(QMouseEvent* e); void dragButtonPressed(); };
Don't put function name in "" ??? The function sig:
QAction *QToolBar::addAction(const QIcon &icon, const QString &text, const QObject *receiver, const char *member)
requires it to be in ""
David
-
- What type is your
editor
? - Do a delete of all files in your debug/release directory, and rebuild. Qt can get in a mess over its
Q_OBJECT
macros and other things, sometimes this happens and this fixes. typedef QObject Inherited;
: probably irrelevant, just wondering whether this could have any detrimental effect on moc etc.dragButtonPressed
is a slot of your own you have created?
Oh, you didn't make clear:
I'm getting a debug output message:
QObject::connect: Use the SLOT or SIGNAL macro to connect DEditStars::dragButtonPressed
At first I thought you meant at compile-time, now I'm thinking you mean at runtime when the
addAction()
is hit?In any case please do the complete rebuild before going any further....
- What type is your
-
Editor is of type DEditStars as you might hope.
Never had a problem using that sort of typedef before.
Yes this is at RUNTIME when addAction is invoked (after a full cleanup and rebuild):
int main(int argc, char *argv[]) { QApplication a(argc, argv); QPixmap p("C:\\Users\\amonra\\Documents\\Astrophotography\\NGC 7789 Caroline's Rose or Herschel's Spiral Cluster\\NGC7789 Edited large.png"); DSSImageWidget w(p); DEditStars editor; QObject::connect(&w, &DSSImageWidget::Image_mousePressEvent, &editor, &DEditStars::mousePressEvent); QToolBar t(&w); QIcon dragRect("C:/Users/amonra/Documents/GitHub/DSS/DeepSkyStacker/Buttons/ButtonSelect_Up.bmp"); t.setOrientation(Qt::Vertical); t.addAction(dragRect, "", &editor, "dragButtonPressed()"); //t.setFixedSize(50, 50); t.setIconSize(QSize(48, 48)); w.setToolBar(&t); w.show(); return a.exec(); }
Debug log snippet:
'DSSImageWidget.exe' (Win32): Loaded 'C:\Qt\5.15.0\msvc2019_64\plugins\imageformats\qwebpd.dll'. Symbols loaded. QObject::connect: Use the SLOT or SIGNAL macro to connect DEditStars::dragButtonPressed() 'DSSImageWidget.exe' (Win32): Loaded 'C:\Windows\System32\d3d9.dll'.
-
-
So
editor
is of typeDEditStars
and notDEditStars *
, right? -
I certainly would not expect it to work with
"dragButtonPressed()"
, it would need to be"dragButtonPressed"
as you showed originally. -
(Temporarily) give up on this constructor. Create the action with an overload which does not take that, and set the signal/slot on the
QAction
'striggered
after it is created. Can you get that to work?
P.S.
[signal]void QAction::triggered(bool checked = false)
Your problem may (well?) be that you need your
dragButtonPressed()
slot to be declared with that (optional) parameter, in order to match correctly? -
-
@Perdrix said in Debug output when calling QToolBar::addAction():
QObject::connect: Use the SLOT or SIGNAL macro to connect DEditStars::dragButtonPressed()
This tells you exactly what the problem is.
It should be:t.addAction(dragRect, "", &editor, SLOT(dragButtonPressed()));
-
@jsulm
The OP is trying to use the following overload:QAction *QToolBar::addAction(const QIcon &icon, const QString &text, const QObject *receiver, const char *member)
https://doc.qt.io/qt-5/qtoolbar.html#addAction-3
The action's
triggered()
signal is connected tomember
inreceiver
.Note how the last argument is of type
const char *
, for the name of a member function. -
@JonB He still has to use SLOT, see https://doc.qt.io/qt-5/qobject.html#connect - it has char* also, but you have to use SLOT/SIGNAL macros, not just plain string containing slot/signal name.
-
but you have to use SLOT/SIGNAL macros, not just plain string containing slot name.
Ohhh, well that's not very clear from the docs: "the name of a member function" :) I took the docs as indicating as he did in his original post!
@Perdrix
So follow @jsulm's answer! Though TBH you would be far better getting rid of allSIGNAL
/SLOT()
macros/methods, and doing it new-style, as I say over & over in this forum :) Then the issue would not arise....P.S.
That would betemplate <typename Functor> QAction *QToolBar::addAction(const QIcon &icon, const QString &text, const QObject *context, Functor functor)
, overload https://doc.qt.io/qt-5/qtoolbar.html#addAction-7. -
@JonB said in Debug output when calling QToolBar::addAction():
getting rid of all SIGNAL/SLOT()
this!
-
In the context of that code I tried:
t.addAction(dragRect, "", &editor, &DEditStars::dragButtonPressed());
and was awarded this nastygram:
1>C:\Users\amonra\Documents\source\repos\QImageView\QImageView\main.cpp(17,53): error C2352: 'DEditStars::dragButtonPressed': illegal call of non-static member function 1>C:\Users\amonra\Documents\source\repos\QImageView\QImageView\deditstars.h(61): message : see declaration of 'DEditStars::dragButtonPressed'
trying with:
t.addAction(dragRect, "", &editor, &editor.dragButtonPressed());
got me:
1>C:\Users\amonra\Documents\source\repos\QImageView\QImageView\main.cpp(17): error C2102: '&' requires l-value
This:
t.addAction(dragRect, "", &editor, SLOT(dragButtonPressed()));
Does work, but it definitely is NOT clear that what you need to code from the docs. If you want me to use the other formats - how do they go?
So hows it supposed to go? -
@Perdrix
Do you know how to callconnect
?
It is exactly the same... -
-
@Perdrix said in Debug output when calling QToolBar::addAction():
Just to be 100% clear, and get you on the right track of new syntax so you will like it(!), as @Pl45m4 has said the whole line needs to be:t.addAction(dragRect, "", &editor, &DEditStars::dragButtonPressed);
Page https://wiki.qt.io/New_Signal_Slot_Syntax gives you comparative examples.