Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 4

Qt-interest Archive, April 2007
SIGNAL emitted but SLOT never called


Message 1 in thread

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 ] 

Message 2 in thread

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 3 in thread

On 12.04.07 12:41:36, Thomas Dähling wrote:
> connect fails when you use custom datatypes in your signals/slots unless you 
> declare your own datatypes with Q_DECLARE_METATYPE.

Thats wrong.

> 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.

Do you get any error messages while running your program? Can you post a
minimal compilable example that reproduces the problem?

Andreas

-- 
 [ signature omitted ] 

Message 4 in thread

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 5 in thread

Till Oliver Knoll schrieb:
> ...
>   of a given class) method and you forgot to call it from within the
>   d'tor, for example
    ^^^^^

c'tor, off course ;)

(Am I the only person who reads his posts /after/ he has sent them?)

;)

Cheers, Oliver


--
 [ signature omitted ] 

Message 6 in thread

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 ]