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. I want to output int instead of a string
Qt 6.11 is out! See what's new in the release blog

I want to output int instead of a string

Scheduled Pinned Locked Moved Unsolved General and Desktop
22 Posts 6 Posters 3.5k 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.
  • L LT-K101

    @JonB Alright, please below is my block of code

    senior_staff_males = '''  
                     SELECT staff_gender, staff_grade,
                     COUNT(*) AS total
                     FROM permanent_staff
                     WHERE staff_gender = 'Male' AND staff_grade = 'Senior Officer'  
                          '''
    Smales_sql = cur.execute(senior_staff_males).fetchall()
    self.ui.label_533.setText(str(Smales_sql [0][0]))
    print(str(Smales_sql [0][0]))
    
    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by JonB
    #11

    @LT-K101
    Just the sort of thing I thought. So you were quite wrong to say originally

    My sql statement returns an int value

    . Now when I run this query in sql it works perfectly with an int value as output.

    Both of these were not true for that query, were they? It is not helpful for you to have claimed what you do above.

    Since the first column returned is staff_gender, str(Smales_sql [0][0]) will presumably return male (or female, but your WHERE prevents that) , just as you show.

    I will leave it to you to think what you actually want from the result set.

    L 1 Reply Last reply
    0
    • JonBJ JonB

      @LT-K101
      Just the sort of thing I thought. So you were quite wrong to say originally

      My sql statement returns an int value

      . Now when I run this query in sql it works perfectly with an int value as output.

      Both of these were not true for that query, were they? It is not helpful for you to have claimed what you do above.

      Since the first column returned is staff_gender, str(Smales_sql [0][0]) will presumably return male (or female, but your WHERE prevents that) , just as you show.

      I will leave it to you to think what you actually want from the result set.

      L Offline
      L Offline
      LT-K101
      wrote on last edited by
      #12

      @JonB This is really confusing because when i run the sql statement in sql it returns total value count which is true, so I was thinking I could convert that to a string in my qt script

      JonBJ 1 Reply Last reply
      0
      • L LT-K101

        @JonB This is really confusing because when i run the sql statement in sql it returns total value count which is true, so I was thinking I could convert that to a string in my qt script

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #13

        @LT-K101
        But that is not what the statement (just) returns, is it?

        Please try to understand the minimal amount. You have SELECT staff_gender, staff_grade, COUNT(*) AS total. How may columns does that return?

        L 1 Reply Last reply
        2
        • JonBJ JonB

          @LT-K101
          But that is not what the statement (just) returns, is it?

          Please try to understand the minimal amount. You have SELECT staff_gender, staff_grade, COUNT(*) AS total. How may columns does that return?

          L Offline
          L Offline
          LT-K101
          wrote on last edited by LT-K101
          #14

          @JonB said in I want to output int instead of a string:

          SELECT staff_gender, staff_grade, COUNT(*) AS total

          It returns three columns namely staff_gender,staff_grade, total respectively when i run in sql with thier values. I get string for the first two columns and an int for the third column but I only need the third value which is the total.

          JonBJ 1 Reply Last reply
          0
          • L LT-K101

            @JonB said in I want to output int instead of a string:

            SELECT staff_gender, staff_grade, COUNT(*) AS total

            It returns three columns namely staff_gender,staff_grade, total respectively when i run in sql with thier values. I get string for the first two columns and an int for the third column but I only need the third value which is the total.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #15

            @LT-K101
            Excellent, and correct. And which column contains the number you are interested in? Once you have answered that, how should Smales_sql [0][0] be that column? What should it be for the column you are interested in?

            You just edited to add:

            I get string for the first two columns and an int for the third column but I only need the third value which is the total.

            Again, excellent and true. So if you tell me "I only need the third value", what have you done/what should you do in your code to access that 3rd column?

            Christian EhrlicherC L 2 Replies Last reply
            3
            • JonBJ JonB

              @LT-K101
              Excellent, and correct. And which column contains the number you are interested in? Once you have answered that, how should Smales_sql [0][0] be that column? What should it be for the column you are interested in?

              You just edited to add:

              I get string for the first two columns and an int for the third column but I only need the third value which is the total.

              Again, excellent and true. So if you tell me "I only need the third value", what have you done/what should you do in your code to access that 3rd column?

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #16

              @JonB said in I want to output int instead of a string:

              Again, excellent and true. So if you tell me "I only need the third value", what have you done/what should you do in your code to access that 3rd column?

              But teacher it's Friday and very late already - can't you do this for me?

              And btw: I though this is a forum about Qt, not python

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              L 1 Reply Last reply
              2
              • JonBJ JonB

                @LT-K101
                Excellent, and correct. And which column contains the number you are interested in? Once you have answered that, how should Smales_sql [0][0] be that column? What should it be for the column you are interested in?

                You just edited to add:

                I get string for the first two columns and an int for the third column but I only need the third value which is the total.

                Again, excellent and true. So if you tell me "I only need the third value", what have you done/what should you do in your code to access that 3rd column?

                L Offline
                L Offline
                LT-K101
                wrote on last edited by LT-K101
                #17

                @JonB Thanks a lot I really appreciate your guidance. i used Smales_sql [0][2] and it worked.

                JonBJ Pl45m4P 2 Replies Last reply
                1
                • Christian EhrlicherC Christian Ehrlicher

                  @JonB said in I want to output int instead of a string:

                  Again, excellent and true. So if you tell me "I only need the third value", what have you done/what should you do in your code to access that 3rd column?

                  But teacher it's Friday and very late already - can't you do this for me?

                  And btw: I though this is a forum about Qt, not python

                  L Offline
                  L Offline
                  LT-K101
                  wrote on last edited by
                  #18

                  @Christian-Ehrlicher I'm really Sorry for disturbing the forum.

                  Christian EhrlicherC 1 Reply Last reply
                  0
                  • L LT-K101

                    @JonB Thanks a lot I really appreciate your guidance. i used Smales_sql [0][2] and it worked.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #19

                    @LT-K101 said in I want to output int instead of a string:

                    i used Smales_sql [0][2]

                    That's much better :) You can see now why you needed to use that, and it's best that you came to that conclusion yourself because then you understand what is going on.

                    L 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @LT-K101 said in I want to output int instead of a string:

                      i used Smales_sql [0][2]

                      That's much better :) You can see now why you needed to use that, and it's best that you came to that conclusion yourself because then you understand what is going on.

                      L Offline
                      L Offline
                      LT-K101
                      wrote on last edited by
                      #20

                      @JonB Yes Yes You guys are the best.

                      1 Reply Last reply
                      1
                      • L LT-K101

                        @Christian-Ehrlicher I'm really Sorry for disturbing the forum.

                        Christian EhrlicherC Offline
                        Christian EhrlicherC Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by
                        #21

                        @LT-K101 said in I want to output int instead of a string:

                        Sorry for disturbing the forum.

                        That's not the point. The point is that people who ask should really try to understand what they're asking and doing instead getting every little step done by someone else.

                        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
                        • L LT-K101

                          @JonB Thanks a lot I really appreciate your guidance. i used Smales_sql [0][2] and it worked.

                          Pl45m4P Online
                          Pl45m4P Online
                          Pl45m4
                          wrote on last edited by Pl45m4
                          #22

                          @LT-K101 said in I want to output int instead of a string:

                          i used Smales_sql [0][2] and it worked.

                          How surprising :)

                          If you knew your int is in column 3, why do you wrote [0][0]? This will always access the first result, which is always a string, when executing your query.

                          Btw: There is a section on this website, dedicated to PyQt questions :)

                          • https://forum.qt.io/category/58/qt-for-python

                          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                          ~E. W. Dijkstra

                          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