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. Qcombobox everytime i choose a name it prints all the name i have on my database this is my code

Qcombobox everytime i choose a name it prints all the name i have on my database this is my code

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 2 Posters 2.5k 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.
  • p3c0P p3c0

    @Gelo Use currentIndexChanged signal and donot use the loop.

    ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #3

    @p3c0 how will i write it?

    1 Reply Last reply
    0
    • p3c0P p3c0

      @Gelo Use currentIndexChanged signal and donot use the loop.

      ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #4

      @p3c0 What loop? the while or for?

      p3c0P 1 Reply Last reply
      0
      • p3c0P Offline
        p3c0P Offline
        p3c0
        Moderators
        wrote on last edited by
        #5

        @Gelo Check this example:
        https://www.tutorialspoint.com/pyqt/pyqt_signals_and_slots.htm

        In the similar way you connect to the currentIndexChanged signal and get the selected index text in the connected slot.

        157

        1 Reply Last reply
        0
        • ? A Former User

          @p3c0 What loop? the while or for?

          p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #6

          @Gelo said in Qcombobox everytime i choose a name it prints all the name i have on my database this is my code:

          @p3c0 What loop? the while or for?

          for

          157

          ? 1 Reply Last reply
          0
          • p3c0P p3c0

            @Gelo said in Qcombobox everytime i choose a name it prints all the name i have on my database this is my code:

            @p3c0 What loop? the while or for?

            for

            ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #7

            @p3c0 i am confused help me with the code please

            1 Reply Last reply
            0
            • p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #8

              @Gelo Sure but first you must become familiar with Qt's Signals and slots mechanism.

              157

              ? 2 Replies Last reply
              1
              • p3c0P p3c0

                @Gelo Sure but first you must become familiar with Qt's Signals and slots mechanism.

                ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #9

                @p3c0 thank you for the thread
                how to convert this into a string

                self.query = QSqlQuery("SELECT name FROM test_table")
                self.comboBox = QComboBox(self)
                self.comboBox.currentIndexChanged.connect(self.selectionchange)
                #
                while(self.query.next()):
                self.comboBox.addItem(self.query.value(0).toString())

                    #
                    self.show()
                    
                def selectionchange(self):
                        print self.comboBox # i want to convert this into a string?
                
                1 Reply Last reply
                0
                • p3c0P p3c0

                  @Gelo Sure but first you must become familiar with Qt's Signals and slots mechanism.

                  ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #10

                  @p3c0 Thank you again so much! i figured it out ! by just adding

                  def selectionchange(self):
                  print self.comboBox.currentText()

                  it prints what i want!

                  Thank you!

                  1 Reply Last reply
                  1
                  • p3c0P Offline
                    p3c0P Offline
                    p3c0
                    Moderators
                    wrote on last edited by
                    #11

                    @Gelo Great!

                    157

                    ? 1 Reply Last reply
                    0
                    • p3c0P p3c0

                      @Gelo Great!

                      ? Offline
                      ? Offline
                      A Former User
                      wrote on last edited by
                      #12

                      @p3c0 Thank you so much! i really appreciate your effort GodBless you !

                      1 Reply Last reply
                      0
                      • p3c0P Offline
                        p3c0P Offline
                        p3c0
                        Moderators
                        wrote on last edited by
                        #13

                        @Gelo Thank You!. I need it :)

                        157

                        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