Results 1 to 7 of 7

Thread: Odd behavior Signals and Slots

  1. #1
    Join Date
    Jan 2006
    Location
    Leiden, the Netherlands
    Posts
    43
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Odd behavior Signals and Slots

    Hello,

    I have this fantastic class like this:

    Qt Code:
    1. class MyDialog : public QDialog
    2. {
    3. Q_OBJECT
    4. public:"
    5. //etc, etc
    6.  
    7. signals:
    8. matrixChanged(D3DXMATRIX const & matrix);
    9. };
    To copy to clipboard, switch view to plain text mode 

    and my happy class using this dialog. defined like this:

    Qt Code:
    1. class MyDialogUser : public QItemDelegate
    2. {
    3. Q_OBJECT
    4. public:
    5. void ShowDialog();
    6.  
    7. private slots:
    8. void OnMatrixChanged(D3DXMATRIX const & matrix);
    9. };
    To copy to clipboard, switch view to plain text mode 

    Now, I connect these signals in the method called ShowDialog. After a debugging the Qt
    meta object I discovered the only way this works is to do it like this:

    Qt Code:
    1. //implementation of ShowDialog
    2. void MyDialogUser::ShowDialog()
    3. {
    4. MyDialog dlg;
    5. connect(&dlg, SIGNAL(matrixChanged(D3DXMATRIX)), this, SLOT(OnMatrixChanged(D3DXMATRIX)));
    6. dlg.exec();
    7. }
    To copy to clipboard, switch view to plain text mode 

    However I would expect (just see some Qt samples) that, regarding the definition of my slot and signal, I am supposed to do it like this:

    Qt Code:
    1. void MyDialogUser::ShowDialog()
    2. {
    3. MyDialog dlg;
    4. connect(&dlg, SIGNAL(matrixChanged(D3DXMATRIX const &)), this, SLOT(OnMatrixChanged(D3DXMATRIX const &)));
    5. dlg.exec();
    6. }
    To copy to clipboard, switch view to plain text mode 

    Is there some explanation for this? Am I doing something wrong in the function definitions? In all other cases I do it in the second way, but only in this class I discovered this thing...

    Regards,
    Arthur

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Odd behavior Signals and Slots

    Probably the implementation of the signal & slot mechanism doesn't recognize your parameter types correctly. Did you get any error messages on the console?

    If you define your parameters this way:
    Qt Code:
    1. matrixChanged( const D3DXMATRIX& matrix );
    To copy to clipboard, switch view to plain text mode 
    it should work.

  3. #3
    Join Date
    Jan 2006
    Location
    Leiden, the Netherlands
    Posts
    43
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Odd behavior Signals and Slots

    Thanks for your input.

    In the debugger I can see that Qt is logging the error (however I don't see it in the VS IDE output window). The reason is simple: it doesn't recognize the signal.

    Strange enough it only works in the example I wrote, no matter how the signal and slot are defined. It works when I define it with 'const D3DXMATRIX &' and connect with only 'D3DXMATRIX'...

    Note that this is the only case in which I experienced this behavior. I have for example some QLineEdit connections defined with (QString const &) which work fine...

    Is it because the struct (DirectX SDK), is not a QObject?

    Arthur
    Last edited by Arthur; 7th April 2006 at 20:00.

  4. #4
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Odd behavior Signals and Slots

    Quote Originally Posted by Arthur
    Thanks for your input.

    Strange enough it only works in the example I wrote. Even if I have a reference parameter only, it doesn't work...

    Note that this is the only case in which I experienced this behavior. Is it because the struct (DirectX SDK), is not a QObject?

    Arthur
    No. In most cases the parameters to a signal or slot are not a QObject, e.g. int float, double, bool, QString, QVariant, etc are not QObjects.

    Did you try what Jacek suggested, i.e. 'const Type &' rather than 'Type const &'?

    Oops, your post changed as I added this, so now it doesn't make as much sense as a reply...

    Make sure you include the header that defines 'D3DXMATRIX' in your header file.
    Last edited by Chicken Blood Machine; 7th April 2006 at 20:03.
    Save yourself some pain. Learn C++ before learning Qt.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Odd behavior Signals and Slots

    Quote Originally Posted by Arthur
    it doesn't recognize the signal.
    Could you post the exact error message? If you add "CONFIG += console" to your .pro file, it should appear on the console.

    Strange enough it only works in the example I wrote, no matter how the signal and slot are defined. It works when I define it with 'const D3DXMATRIX &' and connect with only 'D3DXMATRIX'...
    Well... it looks like that D3DXMATRIX causes the problem. Maybe there should be a #include directive somewhere?

    You might try this (although it probably won't help):
    Qt Code:
    1. typedef D3DXMATRIX Matrix;
    2. ...
    3. matrixChanged( const Matrix& matrix );
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Location
    Leiden, the Netherlands
    Posts
    43
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Odd behavior Signals and Slots

    Quote Originally Posted by jacek
    Could you post the exact error message? If you add "CONFIG += console" to your .pro file, it should appear on the console.
    Do you have any advice on VS 2003 regarding this debugging output? I don't use .pro files, just uncle Bill's .vcproj files. I really would like to see Qt's debug output in the VS debug output window, but I don't know how (I have to admit that I didn't seriously search the forum and help on how to do this).

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Odd behavior Signals and Slots

    Quote Originally Posted by Arthur
    Do you have any advice on VS 2003 regarding this debugging output? I don't use .pro files, just uncle Bill's .vcproj files. I really would like to see Qt's debug output in the VS debug output window, but I don't know how
    I don't use VS, but I guess it should happen automatically when you start the debug version of your program from the VS.

Similar Threads

  1. Signals and Slots
    By 83.manish in forum Qt Programming
    Replies: 3
    Last Post: 30th June 2008, 10:31
  2. Replies: 12
    Last Post: 23rd June 2008, 08:05
  3. Slots or new slots
    By Colx007 in forum Qt Programming
    Replies: 3
    Last Post: 21st January 2008, 17:38
  4. Adding slots in Designer
    By jamos in forum Qt Tools
    Replies: 5
    Last Post: 18th May 2006, 23:28
  5. Missing slots
    By Mariane in forum Newbie
    Replies: 1
    Last Post: 5th February 2006, 01:50

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.