You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

hylke

Trainee

  • "hylke" is male
  • "hylke" started this thread

Posts: 123

Location: Netherlands

Occupation: Student

  • Send private message

1

Monday, April 18th 2005, 5:26pm

Creating a signal

Hello
I would like to create a simple SIGNAL.
But I have no idea how signals work.
I know that slots are just functions of a class that are called whenever a signal is sent.
But how does that work with signals?
Is it like, whenever the signal function is called, the slot function is executed?
And could anoyne please provide me an easy example of how a really simple signal could look like?
Thanx Hylke
Duh

Posts: 2,162

Location: Graz, Austria

Occupation: Student

  • Send private message

2

Monday, April 18th 2005, 5:30pm

You declare signals in the signals: section of the class declaration, just like slots.
But you don't add any body.

At the point where you want to emit the signal you simply write

Source code

1
2
emit signalname(); // no parameters
emit signalname(parametervalue); // with one parameter

The program execution then calls all connected slots and returns from the emit call after the last one.

However you can not assume any odering of slots, they might be executed in any order.

Cheers,
_
Qt/KDE Developer
Debian User

Krasu

Intermediate

  • "Krasu" is male

Posts: 234

Location: Republic of Belarus

  • Send private message

3

Monday, April 18th 2005, 5:30pm

RE: Creating a signal

use QT Assistant, brother :)

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class.h
----------

#include <qobject.h>

class Class : public QObject
{
   Q_OBJECT

   public:
        Class();
        ~Class();

   signals:
         void dosomething();
};

class.cpp
-------------

#include "class.h"

Class::Class() : QObject()
{}

Class::~Class()
{}

.........

example:

class = new Class;

connect(class, SIGNAL(dosomething()), this, SLOT(slotDoSomething()));


You can wake signal manually with "emit dosomething();"

This post has been edited 1 times, last edit by "Krasu" (Apr 18th 2005, 5:31pm)


hylke

Trainee

  • "hylke" is male
  • "hylke" started this thread

Posts: 123

Location: Netherlands

Occupation: Student

  • Send private message

4

Tuesday, April 19th 2005, 7:43pm

Ok, Thanx.
That was easyer than i expected it to be.
Hylke
Duh

5

Wednesday, April 20th 2005, 12:19pm

Hey

use the desiger and first create a slot then create a connections

Now write the code in the .h file

The compile

You can find the actual moc and cpp file generated.

Here u can see the actual code written by the QT Desiger for signal and slot mechanims