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. updating radio buttons programmatically
Forum Updated to NodeBB v4.3 + New Features

updating radio buttons programmatically

Scheduled Pinned Locked Moved Solved General and Desktop
44 Posts 4 Posters 12.4k Views 2 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #34

    That's how I tried it originally, but then they insisted in showing up in separate windows. Can you point me to the right document to read to get them into the edit widget?

    Thanks...

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

      I could have wrote it clearer. Remove them from your original editor and either use designer to create the IpSourceWidget UI or do it by code.

      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
      • mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by
        #36

        OK, this is (yet another) first for me...I assume/hope that it's possible to superimpose my IpSourceWidget onto my EditDialog widget? (If I'm using the write terms)

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

          I think you might be overcomplicating how things are working. IpSourceWidget is just a widget that's slightly more complex than a QLineEdit. In your editor widget, put an empty widget where IpSourceWidget should be and then use the promote feature to use it.

          Or, in the constructor of your editor widget, you can prepend an instance of IpSourceWidget to the layout you are using for your editor widget.

          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
          • mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by
            #38

            OK, I created a new QT designer form class. I'm getting compile errors that suggest my class is incomplete.

            Here's my header file; what might I be missing?

            #include <QGroupBox>
            
            namespace Ui 
            {
                class IpSource;
            }
            
            class IpSource : public QGroupBox
            {
                Q_OBJECT
                Q_PROPERTY(QString ipSource READ ipSource WRITE setIpSource NOTIFY ipSourceChanged USER true)
            
            public:
                explicit IpSource(QWidget *parent = nullptr);
                ~IpSource();
                QString ipSource() const;
            
            signals:
                void ipSourceChanged(const QString &source);
            
            public slots:
                void setIpSource(const QString &source);
            
            private:
                Ui::IpSource *ui;
            };
            

            And the start of my c'tor:

            IpSource::IpSource(QWidget *parent) :
                QGroupBox(parent),
                ui(new Ui::IpSource)
            {
            ...
            

            I get this:
            C:\Users\MZimmers\CD desktop apps\Qt projects\wb_utility\ipsource.cpp:6: error: invalid use of incomplete type 'class Ui::IpSource'
            ui(new Ui::IpSource)
            ^ // caret pointing to IpSource

            1 Reply Last reply
            0
            • M Offline
              M Offline
              medyakovvit
              wrote on last edited by
              #39

              @mzimmers Check that you have

              include "ui_ipsource.h";
              

              in ipsource.cpp file

              mzimmersM 1 Reply Last reply
              0
              • M medyakovvit

                @mzimmers Check that you have

                include "ui_ipsource.h";
                

                in ipsource.cpp file

                mzimmersM Offline
                mzimmersM Offline
                mzimmers
                wrote on last edited by
                #40

                @medyakovvit thanks for looking. Yes, I do have that. Here's the start of my source file:

                #include "ipsource.h"
                #include "ui_ipsource.h"
                
                IpSource::IpSource(QWidget *parent) :
                    QGroupBox(parent),
                    ui(new Ui::IpSource)
                {
                    ui->setupUi(this);
                }
                
                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  medyakovvit
                  wrote on last edited by
                  #41

                  @mzimmers Check that "ui_ipsource.h" contains what you expect.

                  1 Reply Last reply
                  1
                  • mzimmersM Offline
                    mzimmersM Offline
                    mzimmers
                    wrote on last edited by
                    #42

                    Ah...that revealed the problem. In my fumbling around, I'd renamed the class in Designer. I just changed it back, and it seems to be good now. Thanks...now back to my struggles with those radio buttons.

                    1 Reply Last reply
                    0
                    • mzimmersM Offline
                      mzimmersM Offline
                      mzimmers
                      wrote on last edited by mzimmers
                      #43

                      I've added a Widget to my edit dialog, and promoted it to class IpSource. It displays correctly, but I can't access it programmatically, at least not with the "ui->" pointer I'm accustomed to using.

                      Did I miss a step? I've never used promotions before.
                      0_1534868870450_ipsource.PNG

                      EDIT: this question is irrelevant to the thread, so I'm going to ask it in a separate thread.

                      1 Reply Last reply
                      0
                      • mzimmersM Offline
                        mzimmersM Offline
                        mzimmers
                        wrote on last edited by
                        #44

                        OK, I believe I now have this beaten into submission. Here's my understanding of the necessary ingredients:

                        1. upon determining the need for an internal (programmatic) change to the status of the radio buttons, the model needs to be set or updated appropriately:
                            // the IP configuration source.
                            QString qs = QString::fromStdString(msg->getValue(msgTag[TAG_IP_CONFIG_SRC]));
                            QVariant qv = m_model->data(m_model->index(row, TAG_IP_CONFIG_SRC));
                            if (qs != qv)
                            {
                                m_model->setData(m_model->index(row, TAG_IP_CONFIG_SRC), qs);
                                emit ipSourceChanged(qs);
                            }
                        
                        1. a custom designer class, based on QGroupBox, is necessary:
                        class IpSource : public QGroupBox
                        {
                            Q_OBJECT
                            Q_PROPERTY(QString ipSource READ ipSource WRITE setIpSource NOTIFY ipSourceChanged USER true)
                        
                        public:
                            explicit IpSource(QWidget *parent = nullptr);
                            ~IpSource();
                            QString ipSource() const;
                        
                        signals:
                            void ipSourceChanged(const QString &source);
                        
                        public slots:
                            void setIpSource(const QString &source);
                        
                        private:
                            Ui::IpSource *ui;
                        
                        1. from your parent dialog (if that's the right term), create an empty widget, and promote it to your custom widget.
                        2. the syntax for retrieving the value of the radio button group was a little tricky at first, but it goes like this:
                                string s = ui->ipSource->ipSource().toStdString();
                        

                        (you can ignore the StdString part if you're just using QStrings; I have to share my constants header file with a firmware app.

                        If anyone feels that the above needs correction/improvement, please let me know.

                        Thanks to everyone who helped on this.

                        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