PDA

View Full Version : Who can teach me how to creat a new SIGNAL or a SLOT using Qt creator?Yes I'm a pupil



Dave2011
5th August 2011, 12:27
I just know how to write the code,but I don't know how to let them work.Who can tell me how to creat them with Qt Creator?

Axtroz
5th August 2011, 14:58
There's a fine example in the docs ( and online here (http://doc.qt.nokia.com/latest/signalsandslots.html) ).

Here's an example (not a 100% working example):
in the header:


#include <QtGui>

class MyClass : public QWidget
{
Q_OBJECT
public:
MyClass::MyClass();
MyClass::~MyClass();
signals:
void mySig();
public slots:
void mySlot();
};


and the cpp file:


#include "myclass.h"

MyClass::MyClass() {
.....
connect (this, SIGNAL(mySig()), this, SLOT(mySlot());
.....
if (something) { emit mySig(); }
}

MyClass::~MyClass()
{
}

void MyClass::MySlot()
{
.....
doSomething();
.....
}

Dave2011
5th August 2011, 18:01
And then? complie?

Added after 16 minutes:

I'm sorry I haven't understood.More detail please.Thanks!

stampede
5th August 2011, 19:21
Whats wrong with the great Signals And Slots (http://doc.qt.nokia.com/latest/signalsandslots.html) documentation (A Small Example (http://doc.qt.nokia.com/latest/signalsandslots.html#a-small-example) is available there as well) ?

Dave2011
7th August 2011, 09:45
I'm not good at English, you know,it's always a pity for me.I can't understand the documentation accuratly!:(
What I'm needed is a whole example and the steps to complie it!
Thanks to you for help me.:)

finngruwier
7th August 2011, 17:24
For a simple signal/slot example you might take a look at this tread (http://www.qtcentre.org/threads/43719-Connecting-signal-and-slot-fails-in-Symbian-emulator). The code in the post actually works.

Start by making a new "Qt Quick Application" in Qt Creator.