Solved Trouble with signals and slots
-
@VRonin
Hangs describes it the best. Nothing happens even when I click the button again. It feels like it doesn't want to go to the slot. I can click on other buttons after it hangs and does what ever it is supposed to do. -
ok, try replacing
connect(m_mainButton,&QPushButton::clicked,this,&ImageCorrectButton::selectImageFile);
withconnect(m_mainButton,&QPushButton::clicked,[]()->void{qDebug("Entered selectImageFile!");});
and see if that works -
@VRonin
Nothing new happens. "Hangs" at the same location. -
Nothing gets printed in the debug console?!
-
@VRonin
Entered createEditor
Entered image editor
Entered ImageCorrectButton!
m_mainButton clicked!Locals m_mainButton @0x12395cc QPushButton parent @0x12395f0 QWidget this @0x123957c ImageCorrectButton
1 ImageCorrectButton::ImageCorrectButton imagecorrectbutton.cpp 16 0x41e080
2 myDelegate::createEditor mydelegate.cpp 49 0x41c61a
3 QAbstractItemViewPrivate::editor qabstractitemview.cpp 4199 0x15154af1
4 QAbstractItemViewPrivate::openEditor qabstractitemview.cpp 4384 0x15155895
5 QAbstractItemView::edit qabstractitemview.cpp 2676 0x1514fa8e
6 QAbstractItemView::mouseDoubleClickEvent qabstractitemview.cpp 1954 0x1514cf86
7 QWidget::event qwidget.cpp 8789 0x14f26e82
8 QFrame::event qframe.cpp 550 0x1503c188
9 QAbstractScrollArea::viewportEvent qabstractscrollarea.cpp 1213 0x150c1a09
10 QAbstractItemView::viewportEvent qabstractitemview.cpp 1747 0x1514bd6a
11 QAbstractScrollAreaPrivate::viewportEvent qabstractscrollarea_p.h 111 0x1528ad14
12 QAbstractScrollAreaFilter::eventFilter qabstractscrollarea_p.h 127 0x15289b35
13 QCoreApplicationPrivate::sendThroughObjectEventFilters qcoreapplication.cpp 1099 0x1e4ca0e
14 QApplicationPrivate::notify_helper qapplication.cpp 3795 0x14eefb50
15 QApplication::notify qapplication.cpp 3273 0x14eed8b8
16 QCoreApplication::notifyInternal2 qcoreapplication.cpp 988 0x1e4c6e7
17 QCoreApplication::sendSpontaneousEvent qcoreapplication.h 234 0x1526c865
18 QApplicationPrivate::sendMouseEvent qapplication.cpp 2769 0x14eec563
19 QWidgetWindow::handleMouseEvent qwidgetwindow.cpp 617 0x14f3fb2a
20 QWidgetWindow::event qwidgetwindow.cpp 239 0x14f3e75e
... <More> -
ok, let's bring out the guns:
useconnect(m_mainButton,&QPushButton::clicked,[]()->void{Q_ASSERT(false);});
this should crash your program (actually assert but stay with me here) as soon as you pressm_mainButton
[Make sure you compile in debug mode and not release]
-
@VRonin
Nothing happened. Behaves the same way as before. -
shame on me, it was so obvious and I missed it:
QPushButton *m_mainButton = new QPushButton("Click to \n &Select Image",parent) ;
you are shadowing your member, usem_mainButton = new QPushButton("Click to \n &Select Image",this) ;
-
@VRonin said in Trouble with signals and slots:
m_mainButton = new QPushButton("Click to \n &Select Image",this) ;
This is the message I get in output:
Entered createEditor
Entered image editor
Entered ImageCorrectButton!
m_mainButton clicked!
ASSERT: "false" in file ..\Folkfriends_1_0\imagecorrectbutton.cpp, line 18This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
C:\Programming\Projects\build-Folkfriends_1_0-Desktop_Qt_5_7_0_MinGW_32bit-Debug\debug\Folkfriends_1_0.exe exited with code 3 -
we found the problem then.
you can now go back toconnect(m_mainButton,&QPushButton::clicked,this,&ImageCorrectButton::selectImageFile);
and it should work -
@VRonin said in Trouble with signals and slots:
connect(m_mainButton,&QPushButton::clicked,this,&ImageCorrectButton::selectImageFile)
Thank you. It works now. What was actually wrong with it?
-
@gabor53 As @VRonin said you created another button with same name as in your class:
// m_mainButton is a new local variable with same name as in the class QPushButton *m_mainButton = new QPushButton("Click to \n &Select Image",parent) ;
In your class you have
QPushButton *m_mainButton;
right?
But then you create a new one with same name. You just need to remove QPushButton* like this to use m_mainButton from your class:// m_mainButton from the class m_mainButton = new QPushButton("Click to \n &Select Image",parent) ;
So, you did the connection with another button (not the one which is visible).