qt signal/slot auto-connect issue
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
Code:
Q_OBJECT
private:
TColorComboBox* CBoxTraitCouleurs;
....
private Q_SLOTS:
void on_CBoxTraitCouleurs_activated(int);
....
};
File .cpp:
Code:
TBarAffichage
::TBarAffichage(QWidget *parent
): CBoxTraitCouleurs (new TColorComboBox(this)) {}
...
void TBarAffichage::on_CBoxTraitCouleurs_activated(int i){
qDebug() << "activated";
}
...
The TColorComboBox.h:
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
Re: qt signal/slot auto-connect issue
Can you change Q_SLOTS to slots.
Re: qt signal/slot auto-connect issue
Re: qt signal/slot auto-connect issue
Quote:
Originally Posted by
yogeshgokul
Can you change Q_SLOTS to slots.
I can't because i use boost signals and there are conflicts.
Re: qt signal/slot auto-connect issue
Quote:
Originally Posted by
Lykurg
I have write in the constructor and when i execute it gives that:
Code:
QMetaObject::connectSlotsByName: No matching
signal for on_CBoxTraitCouleurs_activated
(int)
Re: qt signal/slot auto-connect issue
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....
Re: qt signal/slot auto-connect issue
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 :)
Re: qt signal/slot auto-connect issue
Quote:
Originally Posted by
yogeshgokul
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
Re: qt signal/slot auto-connect issue
So, is it running or what ?:confused:
Re: qt signal/slot auto-connect issue
Quote:
Originally Posted by
jpn
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
Code:
CBoxTraitCouleurs->setObjectName("CBoxTraitCouleurs");
now it works.
But maybe you are right about making the connect directly.
Thank you very much