[Qt-interest] problem with signal/slot
Atlant Schmidt
aschmidt at dekaresearch.com
Wed Dec 8 18:53:35 CET 2010
All:
> Are you sure the moc compiler is running for you file.
Not just that, but are you sure you're then *USING* the output
of the moc compiler by passing the produced foo_moc.cpp into
your main cpp compilation?
If all that is fine, then the usual problem is a mismatch of signatures
between the slot declaration and the slot usage in the connect()
statement. You show them as both having identical (void) signatures,
but perhaps you simplified that for the e-mail?
Atlant
________________________________
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Brian McKinnon
Sent: Wednesday, December 08, 2010 12:43
To: qt-interest
Subject: Re: [Qt-interest] problem with signal/slot
Are you sure the moc compiler is running for you file. Check the info in:
const QMetaObject* metaObject = obj->metaObject();
QStringList methods;
methods << metaObject->className();
for(int i = metaObject->methodOffset(); i < metaObject->methodCount(); ++i)
methods << QString::fromLatin1(metaObject->method(i).signature());
On Wed, Dec 8, 2010 at 1:20 PM, Mahendra G.R <mahendra at mahendragr.com<mailto:mahendra at mahendragr.com>> wrote:
Hi,
yes i do put it in a seperate cpp file, just to make it look shorter in the mail i did that :), but still no use, it says method is not found. any other reasons?, thanks for your reply.
On Wed, Dec 8, 2010 at 6:08 PM, Xiaolei Shang <xiaolei.shang at cobham.com<mailto:xiaolei.shang at cobham.com>> wrote:
Hi:
Hi guys,
i have a small problem with signal/slot, though i have defined my slot method, i get runtime message saying Object::connect: No such slot CustomScene::updateAlphaValue() , i have defined the method updateAlphaValue() in the customScene class
this is my code :
class CustomScene : public QGraphicsScene
{
Q_OBJECT
public:
CustomScene()
{
alphaSlider = new QSlider(Qt::Horizontal);
alphaSlider->setTickInterval(1);
alphaSlider->setRange(0,255);
alphaSlider->setMinimumSize(105,20);
alphaSlider->move(6,222);
alphaSlider->setToolTip("Opacity");
connect( alphaSlider, SIGNAL(valueChanged(int)), SLOT(updateAlphaValue()) );
//some other stuff
}
public slots :
void updateAlphaValue();
};
--
http://www.mahendragr.com
If you move the declaration of updateAlphaValue() to the front of the definition of the constructor, the compiler should be able to see the function. Like this:
class CustomScene : public QGraphicsScene
{
Q_OBJECT
public slots :
void updateAlphaValue();
public:
CustomScene()
{
alphaSlider = new QSlider(Qt::Horizontal);
alphaSlider->setTickInterval(1);
alphaSlider->setRange(0,255);
alphaSlider->setMinimumSize(105,20);
alphaSlider->move(6,222);
alphaSlider->setToolTip("Opacity");
connect( alphaSlider, SIGNAL(valueChanged(int)), SLOT(updateAlphaValue()) );
//some other stuff
}
...
};
As you define your constructor in your declaration scope. You have to declare a function before you call it. Otherwise, the compiler won't see it. However, in this case, this is not a good way for defining the class as it contains many line codes. Implicitly, it's a online function. I would recommand to put the definition of the constructor in a .cpp file.
Cheers
Xiaolei
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com<mailto:Qt-interest at trolltech.com>
http://lists.trolltech.com/mailman/listinfo/qt-interest
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com<mailto:Qt-interest at trolltech.com>
http://lists.trolltech.com/mailman/listinfo/qt-interest
--
http://www.mahendragr.com
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com<mailto:Qt-interest at trolltech.com>
http://lists.trolltech.com/mailman/listinfo/qt-interest
Click here<https://www.mailcontrol.com/sr/+uFycCxKHE7TndxI!oX7UpIgRUnoDh5vhFRpKQtLJ3x!Pod5OPGm48CfK620UNylItDW1bNQIcTwFL4l1WzKMQ==> to report this email as spam.
________________________________
This e-mail and the information, including any attachments, it contains are intended to be a confidential communication only to the person or entity to whom it is addressed and may contain information that is privileged. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please immediately notify the sender and destroy the original message.
Thank you.
Please consider the environment before printing this email.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101208/ca2a22a6/attachment.html
More information about the Qt-interest-old
mailing list