PDA

View Full Version : Odd behavior Signals and Slots



Arthur
7th April 2006, 17:46
Hello,

I have this fantastic class like this:



class MyDialog : public QDialog
{
Q_OBJECT
public:"
//etc, etc

signals:
matrixChanged(D3DXMATRIX const & matrix);
};


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



class MyDialogUser : public QItemDelegate
{
Q_OBJECT
public:
void ShowDialog();

private slots:
void OnMatrixChanged(D3DXMATRIX const & matrix);
};


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:



//implementation of ShowDialog
void MyDialogUser::ShowDialog()
{
MyDialog dlg;
connect(&dlg, SIGNAL(matrixChanged(D3DXMATRIX)), this, SLOT(OnMatrixChanged(D3DXMATRIX)));
dlg.exec();
}


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:



void MyDialogUser::ShowDialog()
{
MyDialog dlg;
connect(&dlg, SIGNAL(matrixChanged(D3DXMATRIX const &)), this, SLOT(OnMatrixChanged(D3DXMATRIX const &)));
dlg.exec();
}


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

jacek
7th April 2006, 18:08
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:
matrixChanged( const D3DXMATRIX& matrix );it should work.

Arthur
7th April 2006, 19:49
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

Chicken Blood Machine
7th April 2006, 19:59
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.

jacek
7th April 2006, 20:18
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):
typedef D3DXMATRIX Matrix;
...
matrixChanged( const Matrix& matrix );

Arthur
17th April 2006, 21:53
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).

jacek
17th April 2006, 22:08
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.