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. Qt - I want to use the QComboBox after the return/enter is pressed.
Forum Updated to NodeBB v4.3 + New Features

Qt - I want to use the QComboBox after the return/enter is pressed.

Scheduled Pinned Locked Moved Unsolved General and Desktop
25 Posts 5 Posters 4.3k 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.
  • D developer_96

    I have the following problem:

    I'm using the QComboBox of QT to select a path by a Drop & Down. It is working fine after I choose one of the list, the path is automatically update. But now if I want to edit the Path manually by type in a path, I get immediately a warning. So I know that this is happening cause of the argument:

    connect(ui.leftBox, &QComboBox::currentTextChanged, this, &MainCom::updatepath);
    

    So always if I'm going to change the path, for example by changing only one letter or select it by Drop & Down the "currentTextChanged" calls the function 'updatepath'
    So what I want to achieve is that if I'm going to select a path the function should be called normally. But if I'm going to type in a new path or editing the path manually I want that the function will be called after type "return".

    I hope you can help.

    JonBJ Online
    JonBJ Online
    JonB
    wrote on last edited by
    #2

    @developer_96
    Try QComboBox::editTextChanged instead. If that behaves the same, I guess you'll need to pick up QLineEdit *QComboBox::lineEdit() and slot onto QLineEdit::editingFinished() for that.

    1 Reply Last reply
    2
    • D Offline
      D Offline
      developer_96
      wrote on last edited by
      #3

      @JonB i can not use the QLineEdit in my connect.

      jsulmJ 1 Reply Last reply
      0
      • D developer_96

        @JonB i can not use the QLineEdit in my connect.

        jsulmJ Online
        jsulmJ Online
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #4

        @developer_96 said in Qt - I want to use the QComboBox after the return/enter is pressed.:

        i can not use the QLineEdit in my connect.

        Why not? you can get the pointer to line edit from your combo box using QLineEdit *QComboBox::lineEdit() as @JonB pointed out.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • D Offline
          D Offline
          developer_96
          wrote on last edited by
          #5

          @jsulm don't know. I tried to use

          QLineEdit::editingFinished()
          

          in my connect function like:

          connect(ui.leftBox, &QLineEdit::editingFinished, this, &MainCom::updatepath);
          

          but it does not work.

          mrjjM jsulmJ JonBJ 3 Replies Last reply
          0
          • D developer_96

            @jsulm don't know. I tried to use

            QLineEdit::editingFinished()
            

            in my connect function like:

            connect(ui.leftBox, &QLineEdit::editingFinished, this, &MainCom::updatepath);
            

            but it does not work.

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #6

            @developer_96

            hi
            should that not be
            connect(ui.leftBox->lineEdit(), &QLineEdit::editingFinished, this, &MainCom::updatepath);

            1 Reply Last reply
            1
            • D developer_96

              @jsulm don't know. I tried to use

              QLineEdit::editingFinished()
              

              in my connect function like:

              connect(ui.leftBox, &QLineEdit::editingFinished, this, &MainCom::updatepath);
              

              but it does not work.

              jsulmJ Online
              jsulmJ Online
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #7

              @developer_96 said in Qt - I want to use the QComboBox after the return/enter is pressed.:

              but it does not work

              As mentioned already: you need to get the pointer to the line edit using QLineEdit *QComboBox::lineEdit() and use that pointer in the connect.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • D developer_96

                @jsulm don't know. I tried to use

                QLineEdit::editingFinished()
                

                in my connect function like:

                connect(ui.leftBox, &QLineEdit::editingFinished, this, &MainCom::updatepath);
                

                but it does not work.

                JonBJ Online
                JonBJ Online
                JonB
                wrote on last edited by
                #8

                @developer_96

                I guess you'll need to pick up QLineEdit *QComboBox::lineEdit() and slot onto QLineEdit::editingFinished() for that.

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  developer_96
                  wrote on last edited by
                  #9

                  @jsulm how?
                  @mrjj i tried your code. It say "The expression must be of a class type."

                  Regards

                  JonBJ 1 Reply Last reply
                  0
                  • D developer_96

                    @jsulm how?
                    @mrjj i tried your code. It say "The expression must be of a class type."

                    Regards

                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on last edited by JonB
                    #10

                    @developer_96
                    You have a QComboBox. I gave you the method you need to access its QLineEdit. connect() the line edit's QLineEdit::editingFinished signal to the desired slot.

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      developer_96
                      wrote on last edited by
                      #11

                      @JonB i try to acces it by using

                      connect(ui.leftBox, &QLineEdit::editingFinished, this, &MainCom::updatepath);
                      

                      and

                       connect(ui.leftBox->lineEdit(), &QLineEdit::editingFinished, this, &MainCom::updatepath);
                      

                      but it does not work.
                      Thank you for the help.

                      JonBJ 1 Reply Last reply
                      0
                      • D developer_96

                        @JonB i try to acces it by using

                        connect(ui.leftBox, &QLineEdit::editingFinished, this, &MainCom::updatepath);
                        

                        and

                         connect(ui.leftBox->lineEdit(), &QLineEdit::editingFinished, this, &MainCom::updatepath);
                        

                        but it does not work.
                        Thank you for the help.

                        JonBJ Online
                        JonBJ Online
                        JonB
                        wrote on last edited by JonB
                        #12

                        @developer_96
                        The first one will generate a compiler-time error.

                        The second one is correct. What "does not work"? have you tried putting a qDebug() in your &MainCom::updatepath() method, does it get hit?

                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          developer_96
                          wrote on last edited by
                          #13

                          @JonB it says "An incomplete type is not allowed" for &QLineEdit::editingFinished.

                          JonBJ 1 Reply Last reply
                          0
                          • D developer_96

                            @JonB it says "An incomplete type is not allowed" for &QLineEdit::editingFinished.

                            JonBJ Online
                            JonBJ Online
                            JonB
                            wrote on last edited by JonB
                            #14

                            @developer_96
                            Put #include <QLineEdit> at the head of your source (.cpp) file.

                            1 Reply Last reply
                            1
                            • D Offline
                              D Offline
                              developer_96
                              wrote on last edited by
                              #15

                              @JonB thank you. yeah i know but i removed it cause i get this problem after i put in and try to debug: error.JPG

                              jsulmJ 1 Reply Last reply
                              0
                              • D developer_96

                                @JonB thank you. yeah i know but i removed it cause i get this problem after i put in and try to debug: error.JPG

                                jsulmJ Online
                                jsulmJ Online
                                jsulm
                                Lifetime Qt Champion
                                wrote on last edited by
                                #16

                                @developer_96 Please show the relevant code.
                                Does your updatepath() slot have any parameters?

                                https://forum.qt.io/topic/113070/qt-code-of-conduct

                                1 Reply Last reply
                                0
                                • D Offline
                                  D Offline
                                  developer_96
                                  wrote on last edited by
                                  #17

                                  @jsulm
                                  Connect:

                                  connect(ui.leftBox->lineEdit(), &QLineEdit::editingFinished, this, &MainCom::updatepath);
                                  

                                  Updaatepath:

                                  void MainCom::updatepath(const QString& path)
                                  
                                  jsulmJ JonBJ 2 Replies Last reply
                                  0
                                  • Christian EhrlicherC Offline
                                    Christian EhrlicherC Offline
                                    Christian Ehrlicher
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #18

                                    And where do you expect does const QString& path should come from when the signal does not have a parameter?

                                    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
                                    0
                                    • D developer_96

                                      @jsulm
                                      Connect:

                                      connect(ui.leftBox->lineEdit(), &QLineEdit::editingFinished, this, &MainCom::updatepath);
                                      

                                      Updaatepath:

                                      void MainCom::updatepath(const QString& path)
                                      
                                      jsulmJ Online
                                      jsulmJ Online
                                      jsulm
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #19

                                      @developer_96 said in Qt - I want to use the QComboBox after the return/enter is pressed.:

                                      QLineEdit::editingFinished

                                      Has no parameter, so you can't connect it with a slot which expects a parameter. That's exactly what the first error message is saying.

                                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                                      1 Reply Last reply
                                      0
                                      • D developer_96

                                        @jsulm
                                        Connect:

                                        connect(ui.leftBox->lineEdit(), &QLineEdit::editingFinished, this, &MainCom::updatepath);
                                        

                                        Updaatepath:

                                        void MainCom::updatepath(const QString& path)
                                        
                                        JonBJ Online
                                        JonBJ Online
                                        JonB
                                        wrote on last edited by JonB
                                        #20

                                        @developer_96
                                        One/the best way of doing what you want --- pass your own extra parameter to slot --- is to learn to use C++ lambdas here:

                                        connect(ui.leftBox->lineEdit(), &QLineEdit::editingFinished,
                                                this, [this]() { this->updatepath(this->ui.leftBox->lineEdit()->text()); });
                                        // or next line does exactly the same thing, depends which you find clearer
                                        connect(ui.leftBox->lineEdit(), &QLineEdit::editingFinished,
                                                this, [this]() { updatepath(ui.leftBox->lineEdit()->text()); });
                                        
                                        1 Reply Last reply
                                        1
                                        • D Offline
                                          D Offline
                                          developer_96
                                          wrote on last edited by
                                          #21

                                          @JonB @Christian-Ehrlicher @jsulm thank you very much for the answers. I did it now. The function will be called after i type "return". But now if i chose one of the drop & down the programm wants from to type "return" again. My Idea was to type "return" when i manually type a path. When i'm going to select one path of the drop & down i want to update it immediately.

                                          Regards

                                          JonBJ 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