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. QWidget not response on ComboBox action
QtWS25 Last Chance

QWidget not response on ComboBox action

Scheduled Pinned Locked Moved Solved General and Desktop
qwidgetcomboboxsignal & slot
4 Posts 2 Posters 741 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.
  • N Offline
    N Offline
    nebulaekg
    wrote on last edited by
    #1

    Hi, I am new to Qt. I encountered a problem related to QWidget. I setup a QWidget, which has a ComboBox selector. My goal is to use this selector to control some behavior in the main app. I initiated the QWidget in the main ui, but when I change the currentText of the ComboBox, it seems that it does nothing at all. Below is my code:

    surfaceproperty.h:

    namespace Ui {
    class SurfaceProperty;
    }
    
    class SurfaceProperty : public QWidget
    {
        Q_OBJECT
    
    public:
        explicit SurfaceProperty(QWidget *parent = 0);
        ~SurfaceProperty();
    
    public slots:
        void on_selectorSurfaceColormap_currentTextChanged(const QString &arg1);
    
    public:
        Ui::SurfaceProperty *uisp;
    };
    

    surfaceproperty.cpp:

    #include "surfaceproperty.h"
    #include "ui_surfaceProperty.h"
    
    SurfaceProperty::SurfaceProperty(QWidget *parent) :
        QWidget(parent),
        uisp(new Ui::SurfaceProperty)
    {
        uisp->setupUi(this);
    }
    
    SurfaceProperty::~SurfaceProperty()
    {
        delete uisp;
    }
    
    void SurfaceProperty::on_selectorSurfaceColormap_currentTextChanged(const QString &arg1)
    {
               qInfo() << arg1;
    }
    

    Part of main app here:

        QWidget *t = new QWidget;
        uif->uisp->setupUi(t);
        t->show();
        t->setWindowTitle("Surface Properties");
        t->setAttribute(Qt::WA_QuitOnClose, false);
        uif->uisp->selectorSurfaceColormap->setCurrentText("test");
    

    where uif is a SurfaceProperty* I defined here in the main app.

    I did not post my ui file here.

    Basically, I expect that when this part of the main app is called, a widget window appears, and when the ComboBox's currentText is changed, I can get a qInfo() output at the cmd (I build it under Linux). But I only get a widget window when this part is called. I did not see the qInfo() output at all, meaning the ComboBox part is not functional at all.

    Could anyone indicate what is the problem? Did I miss some signal & slot thing?

    Thank you very much!

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Please do not use the auto-connect feature but connect the signals/slots by your own. Maybe you've a type on the member name (selectorSurfaceColormap) so the auto-connect feature can not find the slot.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      N 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        Please do not use the auto-connect feature but connect the signals/slots by your own. Maybe you've a type on the member name (selectorSurfaceColormap) so the auto-connect feature can not find the slot.

        N Offline
        N Offline
        nebulaekg
        wrote on last edited by
        #3

        @Christian-Ehrlicher Hi, Christian, thanks for the reply but I am a little confused. Why the auto-connect feature is not encouraged? Is this true for all windows or only qwidget? I have many auto-connects in the main app, they all work very well. I also did not quite get it on this line: "...you've a type on the member name". Could you indicate? Thanks a lot!

        1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          I said 'Maybe you've a typo...'
          The problem with auto-connect is that you can not be sure if it is really connected (e.g. when there is a typo somewhere in the functions signature or the ui element name) and it easily breaks (e.g. when renaming an ui element).

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          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