Results 1 to 13 of 13

Thread: Unable to detect clicked signal on top layers

  1. #1
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    248
    Thanks
    91
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Unable to detect clicked signal on top layers

    I'm having a button on a widget (homeWidget). The homeWidget is in a stackedwidget which is set as central widget for a main window.
    Now I need to detect a button click signal from homeWidget and trigger an event in CWorker(a subclass of qobject, which I' running as a thread in mainwindow).

    So here I have a clicked signal from homeWidget to centralwidget, on this signal, I'm emitting another signal in centralWidget which is received in mainwindow and connected to a slot in CWorker. Here mainwindow acts as a moderator.

    After doing this, I'm trying to check the clicked signal in CWorker slot using a debug message. I'm not getting debug message in the output. I'm unable to find out why the message isn't getting printed. Please help me solve the issue. Thank you.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Unable to detect clicked signal on top layers

    Are there any warnings in application output?
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    248
    Thanks
    91
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Unable to detect clicked signal on top layers

    No warnings!!

    I'm able to catch the signal from CWorker then pass it on till homeWidget. But the otherway isn't working.

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Unable to detect clicked signal on top layers

    I'm able to catch the signal from CWorker then pass it on till homeWidget. But the otherway isn't working.
    Then it makes me think that signal and slot are not connected, and hence not being called. Show us somthing
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Unable to detect clicked signal on top layers

    When you say CWorker is in a secondary thread, have done that using QObject::moveToThread() or by creating it inside run()?
    Is the secondary thread's event loop running?

    Cheers,
    _

  6. #6
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    248
    Thanks
    91
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Unable to detect clicked signal on top layers

    Pls find the flow of signal from homeWidget to slot in cworker:

    In chomewidget.cpp:
    Qt Code:
    1. connect(m_pbScan, SIGNAL(clicked()), this, SIGNAL(scanBtnClicked())); // this connect is in constructor of homeWidget.cpp
    To copy to clipboard, switch view to plain text mode 

    In centralWidget.cpp:
    Qt Code:
    1. homeWidget = new CHomePage();
    2. connect(homeWidget, SIGNAL(scanBtnClicked()), this, SIGNAL(scanBtnClicked())); // again in constructor
    3. // used similar name for signal in centralWidget.cpp again
    To copy to clipboard, switch view to plain text mode 

    In cmainwindow.cpp
    Qt Code:
    1. centralWidget = new CCentralWidget(); // QStackedWidget
    2. connect(centralWidget, SIGNAL(scanBtnClicked()), worker, SLOT(onScanBtnClick()));// in constructor
    To copy to clipboard, switch view to plain text mode 

    In cworker.h
    Qt Code:
    1. public slots:
    2. void onScanBtnClick();
    To copy to clipboard, switch view to plain text mode 

    In cworker.cpp
    Qt Code:
    1. void CWorker::onScanBtnClick()
    2. {
    3. qDebug("Scan Button Clicked from UI");
    4. }
    To copy to clipboard, switch view to plain text mode 

    Thank you.

  7. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,578
    Thanks
    13
    Thanked 1,584 Times in 1,513 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Unable to detect clicked signal on top layers

    What is a CHomePage and what would make it emit scanBtnClicked?

  8. #8
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    248
    Thanks
    91
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Unable to detect clicked signal on top layers

    Quote Originally Posted by anda_skoa View Post
    When you say CWorker is in a secondary thread, have done that using QObject::moveToThread() or by creating it inside run()?
    Is the secondary thread's event loop running?
    Yes, I did QObject::moveToThread(). I started the secondary thread in qmainwindow.
    The slot which I'm trying to call is not in the loop. It need not be in this case.
    Qt Code:
    1. worker = new CWorker();
    2. thread = new QThread();
    3. worker->moveToThread(thread);
    4. connect(thread, SIGNAL(started()), worker, SLOT(pollSharedMemory()));
    5. connect(trayIcon, SIGNAL(quitButtonClicked()), thread, SLOT(quit()));
    6. connect(trayIcon, SIGNAL(quitButtonClicked()), worker, SLOT(deleteLater()));
    7. connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
    8. shrdMemorySignals();
    9. thread->start();
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by ChrisW67 View Post
    What is a CHomePage and what would make it emit scanBtnClicked?
    CHomePage is one of the widgets on QStackedWidget. QStackedWidget is set as central widget to QMainWindow. So I need to detect the button click signal in CWorker slot (this slot is not running in loop, so need to catch that signal.

    Thank you.
    Last edited by rawfool; 17th June 2013 at 07:09.

  9. #9
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Unable to detect clicked signal on top layers

    and pollSharedMemory() is not running an infinite loop, right?

    Cheers,
    _

  10. #10
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    248
    Thanks
    91
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Unable to detect clicked signal on top layers

    It's in infinite loop: while(1). With 2 secs sleep.
    Now Santosh suggested me to use QTimer from mainwindow itself instead by removing while(1). And timer->moveToThread(thread);
    As of now it's working fine.

    EDIT: BTW Any ideas ?
    Last edited by rawfool; 17th June 2013 at 17:09.

  11. #11
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Unable to detect clicked signal on top layers

    Quote Originally Posted by rawfool View Post
    It's in infinite loop: while(1). With 2 secs sleep.
    Meaning you block the thread's event loop, but the event loop is needed to receive the slot invocation event.

    Not sure why you would need a timer though, sounds unrelated.

    Cheers,
    _

  12. #12
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    248
    Thanks
    91
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Unable to detect clicked signal on top layers

    I'm polling shared memory content, so I created a slot which check the change in data of shared memory & emits a signal. Based on this signal, I disable/enable some widgets.
    And on click events in some widgets, I need to update values of the shared memory (this signal, I wasn't able to receive).
    For ore clarity, I've described my architecture in post #1.
    Thank you for your interest anda_skoa.

  13. #13
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Unable to detect clicked signal on top layers

    For ore clarity, I've described my architecture in post #1.
    That is no where near structure, how can it be architecture? It is a just enough to wear thinking cap.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. How to detect when a QDialog is clicked anywhere?
    By MarcCals in forum Qt Programming
    Replies: 8
    Last Post: 3rd March 2011, 21:24
  2. Replies: 5
    Last Post: 23rd October 2010, 15:17
  3. signal mapping on pushbutton signal clicked
    By wagmare in forum Qt Programming
    Replies: 2
    Last Post: 17th March 2009, 08:54
  4. Unable to detect the library on QT compilation
    By rhonaldmoses in forum Newbie
    Replies: 1
    Last Post: 16th August 2008, 22:01
  5. Replies: 6
    Last Post: 5th December 2007, 23:41

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.