Signals and Slots - why won't this constellation not work
Hey guys,
I've been working with Qt for a few weeks now, still I can't get this specific Signal/Slot/Constellation running.
I've got a class, "Analytic", which is a QObject (defined in Analytics.h) and has got a SLOT called display(), which is called at the end of another function ( in Analytics.cpp).
Now I've got a Mainwindow (defined in MWindow.h) which has got the public SLOT draw_layer() (defined in MWindow.cpp).
What I additionally do is
Analytics *Analy = new Analytics();
connect(Analy, SIGNAL(display()), this, SLOT(draw_layer()));
this is both happening in the main function of my MWindow.cpp
To sum it up: I've got 4 files -> 2 cpp and 2 h. In Header/File 1 I've got a signal, and in Header/File 2 I've got the public SLOT. Qt doesn't give me an error when compiling or while running, but the SLOT is just not triggered, although it works as a function.
Thanks in advance,
Daniel
Re: Signals and Slots - why won't this constellation not work
Show us your code! One guess: did you use the Q_OBJECT macro and did you emit the signal properly?
Re: Signals and Slots - why won't this constellation not work
Hey,
your display() Slot has to be a Signal. This Signal musst be emitted if your Event is processed.
Re: Signals and Slots - why won't this constellation not work
Yeah, I would check that display() slot is defined under as a signal and that you include the Q_OBJECT macro in your class definition and that you emit your signal. (See below)
Code:
{
Q_OBJECT
public:
Analytic();
void process_something()
{
// process something here
emit signalDisplay();
}
signals:
void signalDisplay();
}
Re: Signals and Slots - why won't this constellation not work
Most likely you forgot to emit the display() signal... or if you emit it, check your call/connection to the function/slot in witch you emit the signal.
Re: Signals and Slots - why won't this constellation not work
That was display()-thing was a typo. It is a SIGNAL
Here is my code. I'll just post the relevant parts, but you'll habe to live with the fact, that the naming of my files/variables is german:
DGM_Analyse.h:
Code:
#ifndef DGM_ANALYSE
#define DGM_ANALYSE
#include "Mainheader.h"
{
Q_OBJECT
public:
signals:
void entw_anzeigen();
};
#endif
---------------------------------
DGM_Analyse.cpp:
Well, a lot of functions in here, so the on line about the signal:
Code:
emit entw_anzeigen();
----------------------------------
Hauptfenster.h: (MainWindow)
Code:
#ifndef HAUPTFENSTER_H
#define HAUPTFENSTER_H
#include "DGM_Analyse.h"
{
Q_OBJECT
public:
Hauptfenster();
public slots:
void Entw_Layer();
};
#endif
-----------------------------------------
and finally Hauptfenster.cpp:
Code:
Hauptfenster::Hauptfenster()
{
...
Analytik = new DGM_Analytik(this);
connect(Analytik, SIGNAL(entw_anzeigen()), this, SLOT(Entw_Layer()));
...
}
Hope that helped.
Daniel
Re: Signals and Slots - why won't this constellation not work
You still have to emit your signal!
Re: Signals and Slots - why won't this constellation not work
Didn't I do so by
"emit entw_anzeigen();"?
in the DGM_Analyse.cpp?
Re: Signals and Slots - why won't this constellation not work
In file DGM_Analyse.cpp, the emit entw_anzeigen(); is within a function or slot (most likely, because you probably need to display() when the user does something... ) so check if the function is called or that slot gets connected (with button click or whatever user action it should be connected with).
Re: Signals and Slots - why won't this constellation not work
Quote:
Originally Posted by
FlashMuller
Didn't I do so by
"emit entw_anzeigen();"?
in the DGM_Analyse.cpp?
Yes, but i can't see in which case you emit this signal. So it looks like you did not call this in the case you would like.
Re: Signals and Slots - why won't this constellation not work
Zlatomir is right,
the emit command is inside a function which is a slot itself. Anyway, this works: The Slot-function is being called, doing its job and then emitting the signal. I did a Step-by-step Debug and when reaching the "emit-command" first the moc-file is being opened
Code:
void DGM_Analytik::entw_anzeigen()
{
}
and then Qt jumps through the QObject.cpp file. It breaks at this point:
Code:
if (!sender->d_func()->isSignalConnected(signal_index))
return; // nothing connected to these signals, and no spy
which of course tells me that the connection doesn't seem to work, but doesn't really tell me how to fix it.
Re: Signals and Slots - why won't this constellation not work
In the debug console window, it should state if the connection was made or give an error when the connect() function is called.
Re: Signals and Slots - why won't this constellation not work
It looks right for me, so you have to post your whole code, or we can only guess along.
Re: Signals and Slots - why won't this constellation not work
It should :-)
It doesn't give an error while debugging (QObject: No such Slot or Signal) and it doesn't give any feedback when it returns from the QObject.cpp.
Daniel
4 Attachment(s)
Re: Signals and Slots - why won't this constellation not work
In the attachment you will find the four files. You don't have a working programm with that, but you can try to catch up with me like that. Hope the variable-names aren't a too big problem.
Thanks
P.S.: Please no comments about the rest of my programming ;-)
Re: Signals and Slots - why won't this constellation not work
Noone got an idea? (in other ords: PUSH :p )