Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Moved] Use of QSignalMapper
QtWS25 Last Chance

[Moved] Use of QSignalMapper

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 3.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lorik
    wrote on last edited by
    #1

    Hello,

    I have a problem using QSignalMapper. it does not work and I don't know why

    signalMapper = new QSignalMapper(this);
    signalMapper->setMapping(ui.dcPathSetButton, 1);
    connect(ui.dcPathSetButton, SIGNAL (clicked()), signalMapper, SLOT (map()));
    connect(signalMapper, SIGNAL (mapped(int)), this, SIGNAL (getPath(int)));

    this does work:
    connect(ui.dcPathSetButton, SIGNAL (clicked() ),this,SLOT (getPath() ) );

    comment: I have two functions: getPath() and getPath(int)

    Is there any idea what can be the problem here?

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #2

      Your second connect call is wrong. You are trying to connect a signal to a signal whereas the target should be a slot:

      @
      connect(signalMapper, SIGNAL (mapped(int)), this, SLOT(getPath(int)));
      @

      Running with QT_FATAL_WARNINGS=1 catches this kind of thing.

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        One should be carful in this case. It is perfectly ok to connect a signal to another signal (instead of a slot). In this case once the first signal is fired, the second is fired too (see the example of "QObject::connect() ":http://doc.qt.nokia.com/4.7/qobject.html#connect).

        It is very important, though, to use one of the correct macros SIGNAL(...) or SLOT(...) to wrap the method. You cannot add as method declared as slot to the SIGNAL macro and vice versa. I think that's what you did, and - even worse - you have a method with the same name, but different arguments declared one time as a slot and one time as a signal. I would change this, as it leads to confusion in the future.

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved