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. Direct connect a built-in signal from one class to a slot on another class
Forum Updated to NodeBB v4.3 + New Features

Direct connect a built-in signal from one class to a slot on another class

Scheduled Pinned Locked Moved Unsolved General and Desktop
23 Posts 7 Posters 4.8k Views 3 Watching
  • 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.
  • JonBJ JonB

    @Habibie
    You say this works:

    connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SIGNAL(indexChanged(int)));
    

    and it's inside DialogOne::DialogOne().

    Then you say you changed to

    connect(comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), [=](int index){
    

    still inside DialogOne::DialogOne().

    The compiler says

    ../src/dialogone.cpp:12:13: error: ‘comboBox’ was not declared in this scope

    Why have you changed from ui->comboBox to comboBox?

    H Offline
    H Offline
    Habibie
    wrote on last edited by
    #21

    @JonB said in Direct connect a built-in signal from one class to a slot on another class:

    @Habibie
    You say this works:

    connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SIGNAL(indexChanged(int)));
    

    and it's inside DialogOne::DialogOne().

    The above uses the old string SIGNAL/SIGNAL connection style.

    Then you say you changed to

    connect(comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), [=](int index){
    

    still inside DialogOne::DialogOne().

    The compiler says

    ../src/dialogone.cpp:12:13: error: ‘comboBox’ was not declared in this scope

    Why have you changed from ui->comboBox to comboBox?

    The above uses a new functional connection with lambda.

    BTW, with an old style string SIGNAL/SIGNAL connection, if I change from this

        connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SIGNAL(indexChanged(int)));
    

    to this

        connect(comboBox, SIGNAL(currentIndexChanged(int)), this, SIGNAL(indexChanged(int)));
    

    the compilation spits out the following error messages.

    g++ -c -pipe -g -std=gnu++11 -Wall -Wextra -D_REENTRANT -fPIC -DGIT_VERSION=\"\" -DGIT_HASH=\"febc5d8c3a77a4a9039601f638b0ce220c3b3189\" -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../../SignalsAndSlots-01 -I. -I../include -I/usr/include/x86_64-linux-gnu/qt5 -I/usr/include/x86_64-linux-gnu/qt5/QtWidgets -I/usr/include/x86_64-linux-gnu/qt5/QtGui -I/usr/include/x86_64-linux-gnu/qt5/QtCore -I. -I. -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -o dialogone.o ../src/dialogone.cpp
    ../src/dialogone.cpp: In constructor ‘DialogOne::DialogOne(QWidget*)’:
    ../src/dialogone.cpp:12:13: error: ‘comboBox’ was not declared in this scope; did you mean ‘QComboBox’?
       12 |     connect(comboBox, SIGNAL(currentIndexChanged(int)), this, SIGNAL(indexChanged(int)));
          |             ^~~~~~~~
          |             QComboBox
    make: *** [Makefile:566: dialogone.o] Error 1
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #22

      Hi,

      That's exactly the point of @JonB, there's no reason to remove the ui-> from your code.

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

      H 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        That's exactly the point of @JonB, there's no reason to remove the ui-> from your code.

        H Offline
        H Offline
        Habibie
        wrote on last edited by
        #23

        @SGaist said in Direct connect a built-in signal from one class to a slot on another class:

        Hi,

        That's exactly the point of @JonB, there's no reason to remove the ui-> from your code.

        Got it and thank you for pointing it out.

        1 Reply Last reply
        1

        • Login

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