PDA

View Full Version : qt signal/slot auto-connect issue



parnedo
16th July 2009, 10:51
Hi.

I'm trying the auto-connect feature in my code but i don't arrive to get it working.

this is my code:

File .h

class TBarAffichage : public QToolBar{
Q_OBJECT
private:
TColorComboBox* CBoxTraitCouleurs;
....
private Q_SLOTS:
void on_CBoxTraitCouleurs_activated(int);
....
};
File .cpp:

TBarAffichage::TBarAffichage(QWidget *parent):
QToolBar(parent),
CBoxTraitCouleurs (new TColorComboBox(this)) {}
...
void TBarAffichage::on_CBoxTraitCouleurs_activated(int i){
qDebug() << "activated";
}
...
The TColorComboBox.h:

class TColorComboBox : public QComboBox{
Q_OBJECT
public:
TColorComboBox(QWidget *widget = 0):QComboBox(widget){}
};

When i select the color combobox (CBoxTraitCouleurs) and change it (from red to white) the qDebug isn't launched.
I've tried with others objects and signals but nothing works.

What i'm doing wrong?
I've to put something into the .pro?
I've to add something to the constructor?

Thanks

yogeshgokul
16th July 2009, 11:01
Can you change Q_SLOTS to slots.

Lykurg
16th July 2009, 11:06
You have to call QMetaObject::connectSlotsByName() explicitly.

parnedo
16th July 2009, 12:20
Can you change Q_SLOTS to slots.
I can't because i use boost signals and there are conflicts.

parnedo
16th July 2009, 12:26
You have to call QMetaObject::connectSlotsByName() explicitly.

I have write
QMetaObject::connectSlotsByName(this); in the constructor and when i execute it gives that:


QMetaObject::connectSlotsByName: No matching signal for on_CBoxTraitCouleurs_activated(int)

jpn
16th July 2009, 12:38
QMetaObject::connectSlotsByName() works on OBJECT names, it doesn't know anything about variable names. See QObject::setObjectName(). Anyway, perhaps it would be more straight forward in this case to just establish the connection directly. Auto connections work nicely with UIC produced code, which sets the object names and calls connectSlotsByName() automatically for you....

yogeshgokul
16th July 2009, 12:40
Try adding this line in .pro file.
CONFIG += no_keywords

It tells Qt not to define the moc keywords signals, slots, and emit, because these names will be used by a 3rd party library, e.g. Boost. Then to continue using Qt signals and slots with the no_keywords flag, simply replace all uses of the Qt moc keywords in your sources with the corresponding Qt macros Q_SIGNALS (or Q_SIGNAL), Q_SLOTS (or Q_SLOT), and Q_EMIT.

Enjoy :)

parnedo
16th July 2009, 12:48
Try adding this line in .pro file.
CONFIG += no_keywords

It tells Qt not to define the moc keywords signals, slots, and emit, because these names will be used by a 3rd party library, e.g. Boost. Then to continue using Qt signals and slots with the no_keywords flag, simply replace all uses of the Qt moc keywords in your sources with the corresponding Qt macros Q_SIGNALS (or Q_SIGNAL), Q_SLOTS (or Q_SLOT), and Q_EMIT.

Enjoy :)

That is what i do :) It's because of that i write Q_SLOTS.
Thank you for your reponse

yogeshgokul
16th July 2009, 12:53
So, is it running or what ?:confused:

parnedo
16th July 2009, 12:55
QMetaObject::connectSlotsByName() works on OBJECT names, it doesn't know anything about variable names. See QObject::setObjectName(). Anyway, perhaps it would be more straight forward in this case to just establish the connection directly. Auto connections work nicely with UIC produced code, which sets the object names and calls connectSlotsByName() automatically for you....

That's it.

if i add
CBoxTraitCouleurs->setObjectName("CBoxTraitCouleurs"); now it works.

But maybe you are right about making the connect directly.

Thank you very much