Results 1 to 3 of 3

Thread: signal ending nowhere...

  1. #1
    Join Date
    Jul 2009
    Location
    Italy, Pieve Ligure (GE)
    Posts
    55
    Thanks
    7
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question signal ending nowhere...

    I thought I know the basics of signals and slots but this keeps eluding me. I searched the fora, but none of the suggestions in similar cases were applicable or solved the problem. This is the scenario:

    1) my main window is a QWidget
    2) inside it, potentially through a hierarchy of container widgets, there is a number of QLabel-derived widgets
    3) when one of the latter is clicked I want a slot in the main window to be called, with some parameters (these params are 1 of the reasons I did not use the standard clicked() signal of QPushButton),

    Some code. (Part of) the QLabel-derived widget definition:
    Qt Code:
    1. class CHouse : public QLabel
    2. {
    3. Q_OBJECT
    4. [...]
    5. protected:
    6. void mouseReleaseEvent(QMouseEvent * pEvent); // reimplemented from QWidget
    7. signals:
    8. void houseClicked(int nHouse);
    9. [...]
    10. };
    To copy to clipboard, switch view to plain text mode 
    In mouseReleaseEvent(), the signal is emitted:
    Qt Code:
    1. void CHouse::mouseReleaseEvent(QMouseEvent * pEvent)
    2. {
    3. if( /* some tests on internal object data */)
    4. emit houseClicked(m_nHouse);
    5. }
    To copy to clipboard, switch view to plain text mode 
    The main window definition:
    Qt Code:
    1. class CMainWindow : public QWidget
    2. {
    3. Q_OBJECT
    4.  
    5. [...]
    6. CHouse * m_pHouse[MNC_MAX_NUM_OF_ROWS][MNC_MAX_NUM_OF_COLS];
    7. public slots:
    8. void MoveDo(int nHouse);
    9. [...]
    10. };
    To copy to clipboard, switch view to plain text mode 
    This is where the children widgets are created and their signal connected to the main window slot:
    Qt Code:
    1. bool CMainWindow::InitUI(void)
    2. { int nCol, nRow;
    3. int nHouse;
    4. bool bRes;
    5.  
    6. [...]
    7. for(nRow=0; nRow < m_nNumOfRows; nRow++)
    8. { for(nCol=0; nCol < m_nNumOfCols; nCol++)
    9. { nHouse = ...;
    10. if( (m_pHouse[nRow][nCol]=new CHouse(nHouse, this)) != NULL)
    11. bRes = connect(m_pHouse[nRow][nCol], SIGNAL(houseClicked(int)), this, SLOT(MoveDo(int)));
    12. }
    13. }
    14. [...]
    15. }
    To copy to clipboard, switch view to plain text mode 
    Result:
    1) The code compiles correctly
    2) At run time connect() returns true
    3) CHouse::mouseReleaseEvent() is properly called and the emit houseClicked(m_nHouse); line executed when needed
    4) no warning or error is issued while debugging
    BUT
    5) MoveDo() slot is never called.

    I have tried replacing the SLOT(...) with, say, qApp, SLOT(quit()) or with another dummy slot added to CHouse: in no case the connected slot was called.

    I traced the emit source code down to qobject.cpp, line 3047 in function void QMetaObject::activate(QObject *sender, int from_signal_index, int to_signal_index, void **argv) where the connection list for the sender appears to be empty!

    Other signals connected from other children widgets (QPushButton in this case) to other slots of the main window do work.

    What am I doing wrong?

    Thanks,
    M.

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: signal ending nowhere...

    can you provide a minimal compilable example which reproduces the problem?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Jul 2009
    Location
    Italy, Pieve Ligure (GE)
    Posts
    55
    Thanks
    7
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: signal ending nowhere...

    Thanks for the reply, spirit!

    things are getting more and more interesting: when I prepared a bare-bones compilable sample and I tried it, of course it WORKED!

    Now, the homework is to add pieces back and see where the problem pops up again. Back to coding...

    Thanks,

    M.

Similar Threads

  1. pthread instead QThread
    By brevleq in forum Qt Programming
    Replies: 8
    Last Post: 23rd December 2008, 07:16
  2. Connection of custon signals/slots
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 07:04
  3. Possible signal mapper problem
    By MarkoSan in forum Qt Programming
    Replies: 13
    Last Post: 25th January 2008, 13:11
  4. Replies: 2
    Last Post: 17th May 2006, 21:01

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.