Odd behavior Signals and Slots
Hello,
I have this fantastic class like this:
Code:
{
Q_OBJECT
public:"
//etc, etc
signals:
matrixChanged(D3DXMATRIX const & matrix);
};
and my happy class using this dialog. defined like this:
Code:
{
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:
Code:
//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:
Code:
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
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:
Code:
matrixChanged( const D3DXMATRIX& matrix );
it should work.
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
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.
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.
Quote:
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):
Code:
typedef D3DXMATRIX Matrix;
...
matrixChanged( const Matrix& matrix );
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).
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.