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. Everytime i choose a name everything prints up records is from my database if i remove the while loop the name will not appear on the combobox
Forum Updated to NodeBB v4.3 + New Features

Everytime i choose a name everything prints up records is from my database if i remove the while loop the name will not appear on the combobox

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 1.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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by VRonin
    #1
    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())    
            #
        def selectionchange(self):
            for count in range(self.comboBox.count()):
                print self.comboBox.itemText(count)
            self.show()
    

    Edit by VRonin: in python indentation is essential. use ``` at the beginning and end of your code to highlight it

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      Everytime i choose a name everything prints up records is from my database if i remove the while loop the name will not appear on the combobox

      Yes, this is the behaviour you coded. what did you want to achieve instead?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      ? 2 Replies Last reply
      1
      • VRoninV VRonin

        Everytime i choose a name everything prints up records is from my database if i remove the while loop the name will not appear on the combobox

        Yes, this is the behaviour you coded. what did you want to achieve instead?

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

        @VRonin everytime i choose a name i only want it to display what i choose eg. like this if i choose "gelo" the chosen name will only appear not all of the name in my query it happens when i choose "gelo" all of the names appears

        1 Reply Last reply
        0
        • VRoninV VRonin

          Everytime i choose a name everything prints up records is from my database if i remove the while loop the name will not appear on the combobox

          Yes, this is the behaviour you coded. what did you want to achieve instead?

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

          @VRonin i think the problem is in the while loop

          mrjjM 1 Reply Last reply
          0
          • ? A Former User

            @VRonin i think the problem is in the while loop

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

            @Gelo
            Hi its not a bug or problem ?
            You ask it to to do so.

            self.query = QSqlQuery("SELECT name FROM test_table") // get all names from table

            FOR ALL NAMES IN TABLE
            ADD TO COMBOBOX EACH OF THEM

                while(self.query.next()): 
                    self.comboBox.addItem(self.query.value(0).toString())    
            

            So its very unclear how you want it to work.

            • i choose a name i only want it to display what i choose
              So if combox is NOT to have all the names, how can u then choose in the first place.

            If u mean like this
            List is
            A
            B
            C

            You choose B
            The list is cleared and now ONLY contains B

            But then u cant reselect a new one, say A.
            So i dont get your structure or use case.
            Unless its oK that user cant select new after first selection.

            1 Reply Last reply
            2
            • VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6

              said in Everytime i choose a name everything prints up records is from my database if i remove the while loop the name will not appear on the combobox:

              for count in range(self.comboBox.count()):
              print self.comboBox.itemText(count)

              for count in range(self.comboBox.count()):
                          print self.comboBox.itemText(count)
              

              this prints all the items

              print self.comboBox.itemText(self.comboBox.currentIndex())
              

              prints just the current

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              ? 1 Reply Last reply
              2
              • VRoninV VRonin

                said in Everytime i choose a name everything prints up records is from my database if i remove the while loop the name will not appear on the combobox:

                for count in range(self.comboBox.count()):
                print self.comboBox.itemText(count)

                for count in range(self.comboBox.count()):
                            print self.comboBox.itemText(count)
                

                this prints all the items

                print self.comboBox.itemText(self.comboBox.currentIndex())
                

                prints just the current

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

                @VRonin Thanks men already solve the problem :)

                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