Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qt4 clear() issue : Am I using it right?

Qt4 clear() issue : Am I using it right?

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 3 Posters 1.8k Views 1 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.
  • A Offline
    A Offline
    adiQt4
    wrote on last edited by
    #1

    Hi I am new to qt4 and I'm trying developing a framwork which includes certain topic(labels) to be added to the combo box. Adding topics to a combo box was a success but at ceratin point I need to Refresh the GUI and load the topics to their default state.

    The code itself is called when a the following code is executed:

    @ui_.refresh_topics_push_button->setIcon(QIcon::fromTheme("view-refresh")); connect(ui_.refresh_topics_push_button, SIGNAL(pressed()), this, SLOT(updateTopicList()));@

    Through the function updateTopicList() ui_.topic->clear() is called. But on excecution of this code the control jumps to another function and executes it.

    I also use the following snippet which contains the function which is accedentally executed. (onTopicChanged())
    @connect(ui_.topics_combo_box, SIGNAL(currentIndexChanged(int)), this, SLOT(onTopicChanged(int)));@

    Any help is appreciated

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      This is the correct behaviour. It is not accidental. Since combobox list is cleared, index changed. Hence slot topicChanged is called. You can do the following in your slot(onTopicChanged..)

      void onTopicChanged(int a) {
      if ( a== -1) return i.e don't do anything.

      }

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • A Offline
        A Offline
        adiQt4
        wrote on last edited by
        #3

        No changes in the output. I have called the clear() twice in the updateList() is that the reason your solution is not working?

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

          Hi and welcome to devnet,

          What do you mean by not working ? After calling clear are you repopulating the comboboxes ?

          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
          • dheerendraD Offline
            dheerendraD Offline
            dheerendra
            Qt Champions 2022
            wrote on last edited by
            #5

            What is not working for you ?

            1. Is it the issue of combo box not cleared
            2. Is the issue of curentIndex slot is getting called ?

            I have done simple program for you. Check it.

            @ QComboBox box;
            box.addItem("pthinks.com");
            box.addItem("Dheeru");
            box.addItem("qt-project");
            box.addItem("Raj");

            box.show();
            
            QPushButton buton("Clearme");
            buton.show();
            
            QObject::connect(&buton,SIGNAL(clicked()),&box,SLOT(clear()));
            QObject::connect(&box,SIGNAL(currentIndexChanged(int)),&w,SLOT(topicChanage(int)));
            

            void MainWindow::topicChanage(int va){
            qDebug() << " Topic changed" << va << endl;
            if (va == -1){
            qDebug() << "List is cleared. Dont do anything" <<endl;
            }
            }

            @

            Now if you give exact issue, we can help you.

            Dheerendra
            @Community Service
            Certified Qt Specialist
            http://www.pthinks.com

            1 Reply Last reply
            0
            • A Offline
              A Offline
              adiQt4
              wrote on last edited by
              #6

              Dheerendra- your suggestion worked. I had included a blank append in one of the topic @topic.append("") @ . Hence, the index containing the actual topic started when index=1. Now its working perfectly. Thanks again

              1 Reply Last reply
              0
              • A Offline
                A Offline
                adiQt4
                wrote on last edited by
                #7

                @SGaist- Thanks for the greetings. I got my problem solved

                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