PDA

View Full Version : QLabel's linkActivated() signal in QT 4.2



gsQT4
15th March 2007, 16:29
I've compiled and installed QT 4.2.2 OpenSource version for linux. I noticed the documentation says there are two new signals for the QLabel object. Those are linkActivated() and linkHovered(). I tried to connect the linkActivated() signal for one of my working app's to a slot. The app's form was created via QT Designer. It compiles fine, no errors or warnings. When I run the app, I get a message that the signal does not exist. Does anyone know what I may be missing?

Thanks,
Glenn

high_flyer
15th March 2007, 16:46
could you show us your connect() statment and the error from the console (copy paste)

wysota
15th March 2007, 17:13
Most probably you've run onto one of these (http://www.qtcentre.org/forum/faq.php?faq=qt_signalslot).

gsQT4
15th March 2007, 17:30
I'm not at home, so I cannot send you the message from KDevelop. Here is the connect string I used in my app's constructor:

connect(label_2, SIGNAL(linkActivated()), this, SLOT(myslot()));

From what I saw in the link Wysota had in his reply my connect string should be like this:

connect(label_2, SIGNAL(linkActivated(const QString & )), this, SLOT(myslot()));

Is that correct?

Thanks,
Glenn

high_flyer
15th March 2007, 17:36
actually it should be:


connect(label_2, SIGNAL(linkActivated(const QString & )), this, SLOT(myslot(const QString &)));

gsQT4
15th March 2007, 18:50
Thanks for the help. I'll try it out tonight.

This is probably a dumb question, but what does the (const QString & ) reference?

high_flyer
15th March 2007, 19:02
From the docs:


void QLabel::linkActivated ( const QString & link ) [signal]

This signal is emitted when the user clicks a link. The URL referred to by the anchor is passed in link.

This function was introduced in Qt 4.2.

wysota
15th March 2007, 21:03
The slot can have no arguments, but I doubt you'll be able to do anything useful then :)

gsQT4
15th March 2007, 23:52
OK. Thanks again. I'm not trying to open a link. I'm filling a QPUListView object with QLabel objects. This would be similar to some of the Task Panel tasks you see on some .Net applications. When the user clicks the label, it needs to emit a signal so the connected slot can be executed. Hopefully the linkActivated signal will work.

gsQT4
16th March 2007, 15:32
Thanks Guys. That worked. Once I realized how to set the anchor and link via QT Designer, it worked perfectly.

Glenn