Qt-interest Archive, April 2007
Antw: Re: SIGNAL emitted but SLOT never called
Message 1 in thread
Hi Thomas,
i tried that but first i got several compile errors and second, and more
important, i use many custom classes in combination with SIGNAL and
SLOT.
Christian Rengstl M.A.
Klinik und Poliklinik fÃr Innere Medizin II
Kardiologie - Forschung
UniversitÃtsklinikum Regensburg
B3 1.388
Franz-Josef-Strauss-Allee 11
93053 Regensburg
Tel.: +49-941-944-7230
>>> Thomas DÃhling <t.daehling@xxxxxxxxxxxxxx> 12.04.07 12.41 Uhr >>>
Hi Christian,
connect fails when you use custom datatypes in your signals/slots unless
you declare your own datatypes with Q_DECLARE_METATYPE.
Regards,
Thomas
Christian Rengstl schrieb:
> Hi list,
>
> in the following snippet the SIGNAL is definitely emitted (added a
cout
> in the SIGNAL in the moc file), but the corresponding SLOT is never
> called even though both classes have Q_OBJECT included and inherit
from
> QObject or a QWidget. Maybe i am missing a very important point, but
> since last evening i haven't been able to find the mistake.
>
> TexiProject *tp = _store->getCurrentProject();
> connect(tp, SIGNAL(bibtexItemAddedToProject(TexiProjectBibtexItem *)),
> _ptw, SLOT(addBibtexItem(TexiProjectBibtexItem *)));
> connect(tp, SIGNAL(bibtexItemAddedToProject(TexiProjectBibtexItem *)),
> _proc, SLOT(addBibtexItem(TexiProjectBibtexItem *)));
>
> The objects _ptw and _proc both have a SLOT with the same name which
> does something different though.
>
> I appreciate any help/advice/hint...
>
>
> Christian Rengstl M.A.
> Klinik und Poliklinik fÃr Innere Medizin II
> Kardiologie - Forschung
> UniversitÃtsklinikum Regensburg
> B3 1.388
> Franz-Josef-Strauss-Allee 11
> 93053 Regensburg
> Tel.: +49-941-944-7230
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
"unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
--
[ signature omitted ]
Message 2 in thread
I checked all of it: there are no output messages on the console, the
signals are emitted, which i checked by including a cout << "hello"
inside the moc file, the moc files are updated and there are no argument
names, either. Anyway, i fixed it with a workaround which is not as
elegant and comfortable as signals and slots, but at least it worked.
The strangest thing, i have the same connect somewhere else in my app
just that the emitter is a different class, but the receivers and the
slots/signals are the same and there it works...
Christian Rengstl M.A.
Klinik und Poliklinik fÃr Innere Medizin II
Kardiologie - Forschung
UniversitÃtsklinikum Regensburg
B3 1.388
Franz-Josef-Strauss-Allee 11
93053 Regensburg
Tel.: +49-941-944-7230
>>> Till Oliver Knoll <oliver.knoll@xxxxxxxxxxx> 12.04.07 14.15 Uhr >>>
Christian Rengstl schrieb:
> Hi list,
> ...
> TexiProject *tp = _store->getCurrentProject();
> connect(tp, SIGNAL(bibtexItemAddedToProject(TexiProjectBibtexItem *)),
> _ptw, SLOT(addBibtexItem(TexiProjectBibtexItem *)));
> connect(tp, SIGNAL(bibtexItemAddedToProject(TexiProjectBibtexItem *)),
> _proc, SLOT(addBibtexItem(TexiProjectBibtexItem *)));
The above looks syntactically correct to me, so here are the Usual
Suspects:
- Watch on the console for suspicious "No such signal/slot" Qt messages
- Make sure the path of execution actually hits your "connect"
statements above, /before/ you expect your slot being called; which
seems vey logic, off course, but depending on your context you
might have a "frenchConnection()" (which connects all signals/slots
of a given class) method and you forgot to call it from within the
d'tor, for example
- Make sure the moc_files are updated when changing the corresponding
*.h files. When in doubt do a "make distclean" and/or remove
all moc_* files manually, then recompile from scratch
- Even though you did not get it wrong above, but the following cannot
be stressed enough (and it's a typical copy/paste-mistake not only
done by beginners):
DON'T write any argument names in the connect statement!
// WRONG
connect(tp, SIGNAL(bibtexItemAddedToProject(Item *item)),
_proc, SLOT(addBibtexItem(Item *item)));
Hope that gives you some leads.
Cheers, Oliver
--
[ signature omitted ]
Message 3 in thread
No, unfortunately none of the two SLOTs is called. Anyway I'll try
changing the name of the SLOT to see what happens. Never thought about
that actually...
Christian Rengstl M.A.
Klinik und Poliklinik fÃr Innere Medizin II
Kardiologie - Forschung
UniversitÃtsklinikum Regensburg
B3 1.388
Franz-Josef-Strauss-Allee 11
93053 Regensburg
Tel.: +49-941-944-7230
>>> "Murphy, Sean M." <sean.murphy@xxxxxxxxxx> 12.04.07 19.43 Uhr >>>
I think I may have a similar problem. Like you I had two classes that
had identically named slots, so something like:
classA::mySlot();
classB::mySlot();
Then in my code I had:
classA* A;
classB* B;
connect(someButton, SIGNAL(clicked()), A, SLOT(mySlot()));
connect(someButton, SIGNAL(clicked()), B, SLOT(mySlot()));
So the idea was that when "someButton" was clicked, slots in both A and
B would get called. However when I ran it, classA::mySlot() would get
called TWICE and classB::mySlot() would never get called. I changed the
names of the functions to:
classA::mySlotA();
classB::mySlotB();
And changed my connect statements to match the new functions names and
the problem went away. I never filed a bug on this because at the time
I was on a deadline, but as soon as I read your question I remembered
it. Maybe I'll try to see if I can come up with a minimum compilable
example...
So in your case are either slot (the one in _ptw and the one in _proc)
getting called? Is it getting called twice?
Sean
-----Original Message-----
From: Christian Rengstl
[mailto:Christian.Rengstl@xxxxxxxxxxxxxxxxxxxxxxxx]
Sent: Thursday, April 12, 2007 6:36 AM
To: qt-interest@xxxxxxxxxxxxx
Subject: SIGNAL emitted but SLOT never called
Hi list,
in the following snippet the SIGNAL is definitely emitted (added a cout
in the SIGNAL in the moc file), but the corresponding SLOT is never
called even though both classes have Q_OBJECT included and inherit from
QObject or a QWidget. Maybe i am missing a very important point, but
since last evening i haven't been able to find the mistake.
TexiProject *tp = _store->getCurrentProject(); connect(tp,
SIGNAL(bibtexItemAddedToProject(TexiProjectBibtexItem *)),
_ptw, SLOT(addBibtexItem(TexiProjectBibtexItem *)));
connect(tp, SIGNAL(bibtexItemAddedToProject(TexiProjectBibtexItem *)),
_proc, SLOT(addBibtexItem(TexiProjectBibtexItem *)));
The objects _ptw and _proc both have a SLOT with the same name which
does something different though.
I appreciate any help/advice/hint...
Christian Rengstl M.A.
Klinik und Poliklinik fÃr Innere Medizin II Kardiologie - Forschung
UniversitÃtsklinikum Regensburg
B3 1.388
Franz-Josef-Strauss-Allee 11
93053 Regensburg
Tel.: +49-941-944-7230
--
[ signature omitted ]