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. How to display data returned from Oracle procedure in a different order in QTableWidget?
Forum Updated to NodeBB v4.3 + New Features

How to display data returned from Oracle procedure in a different order in QTableWidget?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 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.
  • G Offline
    G Offline
    Goldglv
    wrote on last edited by
    #1

    I have some data returned from an Oracle stored proc in this order:

    Col1, Col2, Col3, Col4, Col5

    But I want to display it in my QTableWidget like this:

    Col2, Col5, Col3, Col4

    Col1 is a primary key so I don't want it displayed in the table.

    Now this is a very simple example and I know I can use setColumnHidden and moveSection but in my app there are screens that have 50+ columns, this would obviously take forever,

    Is there a more efficient way to do this? I have many stored procs that return data in a certain order but I don't want to display it in that order to the user in my QTableWidget. Using PYQT5, displaying data in a QTableWidget. I will have some comboBoxes, Date fields, strings, integers....

    Any type of sample code would be great but anything to get me pointed in the right direction would be helpful....

    l_query = cursor.callproc('MYPROC_PD', (l_cur,))
    l_results = l_query[0]
    allSQLRows = l_results.fetchall()

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

      Hi,

      A proxy model comes to mind for that see QAbstractProxyModel and the classes related.

      Hope it helps

      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
      • G Offline
        G Offline
        Goldglv
        wrote on last edited by
        #3

        Currently I'm using:
        Import cx_oracle
        Connection = cx_oracle.connect()
        Cursor = connection.cursor()
        ProcResults =cursor.callproc()

        I'm assuming I can't use this now and need to use something from QsqlQuery? Can I pass that a stored procedure?

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

          Sorry, I've read QTableView rather than Widget.

          If you populate a QTableWidget with the result of your query you don't need any special stuff, just put the data where you want them directly.

          If you take the QTableView + QSqlQueryModel then you should take a look at the SQL driver chapter of Qt's documentation where the support for stored procedure is discussed.

          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
          • G Offline
            G Offline
            Goldglv
            wrote on last edited by
            #5

            I just thought it wouldn't be very clean to just say:

            Query result(3) put into 6th column in table widget and so on.....

            Thought there may be a cleaner way to link result set and column positions.

            Is there an advantage of using qtTableView in your 2nd example over what I'm currently doing?

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

              You avoid having to create and/or update and/or re-create items for your QTableWidget when you call the stored procedure again.

              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

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved