Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [SOLVED] signalMapper - mapped SIGNAL with custom Widgets

[SOLVED] signalMapper - mapped SIGNAL with custom Widgets

Scheduled Pinned Locked Moved Mobile and Embedded
3 Posts 2 Posters 1.2k 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.
  • P Offline
    P Offline
    perez.sgo
    wrote on last edited by
    #1

    Hi,

    I'm trying connect a single dial with several custom widgets, according with which actual widget has been selected. Only one custom widget at a time can be connected to the dial.
    I've succesfully solved it with signalMapper as referenced in "signalMapper documentation":http://qt-project.org/doc/qt-4.8/qsignalmapper.html.

    Here is my code:
    @
    {
    QSignalMapper *signalMapper = new QSignalMapper(this);
    signalMapper->setMapping(widgetTest, (QWidget)widgetTest);
    signalMapper->setMapping(widgetTest2, (QWidget)widgetTest2);

    connect(widgetTest, SIGNAL(mouseClickEvent()),
            signalMapper, SLOT (map()));
    connect(widgetTest2, SIGNAL(mouseClickEvent()),
            signalMapper, SLOT (map()));
    
    connect(signalMapper, SIGNAL(mapped(QWidget*),
            this, SLOT(slotMainWindow(QWidget*)));
    
    lastActiveWidget = NULL;
    

    }

    void MainWindow::slotMainWindow(QWidget *actualActiveWidget){

    if(lastActiveWidget!=NULL){
        qDebug("actualActiveWidget != NULL");
        disconnect(dial, SIGNAL(valueChanged(int)),lastActiveWidget,SLOT(setMainValue(int)));
    }
    lastActiveWidget = actualActiveWidget;
    connect(dial, SIGNAL(valueChanged(int)),actualActiveWidget,SLOT(setMainValue(int)));
    

    }@

    My doubt is about the mapped SIGNAL: it is only possible to have int, Qstring, QObject* or QWidget* as arguments, but i need to have MyCustomWidget as an argument. Because MyCustomWidget inherits QWidget, it is possible to have it running treating MyCustomWidget as a QWidget for the signals, but although it works, I am not 100% sure if it's correct to work like that, having consecuences in the future.

    Does anybody knows if these approach is ok or should try another way?

    Thanks in advance.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      That's the correct usage of QSignalMapper. One thing though, don't use c-style caste with QObjects, you have qobject_cast for that. But in this case, you don't need any cast at all

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • P Offline
        P Offline
        perez.sgo
        wrote on last edited by
        #3

        Thanks SGaist for the answer and for the advice, appreciate it a lot!.

        Regards,

        Santiago

        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