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. Struct, Class or Enum? What should I use to store data from sql query and display to QLineEdit
QtWS25 Last Chance

Struct, Class or Enum? What should I use to store data from sql query and display to QLineEdit

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 333 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on 20 Oct 2021, 19:41 last edited by
    #1

    Hello all,
    I have a QListWidget where I can select from a variety of names. When I click on a name in the QListWidget, a database query is made and further data such as name, genus, species, synonyms etc. is loaded. This data should be displayed in different QLineEdits + a QListWidget + a QPlainTextEdit, edited if necessary and saved back to the database.

    What is the best way to proceed with something like this? Should I create a class, a struct or rather use an enum to store the data and integrate it into the individual fields? How do you do something like this?

    About the database:
    Should I rather make a query where the data is fetched from several tables or query each table separately? Which is the better approach?

    As background still: The data must be able to be changed only from the data base into the GUI, there and be pushed again back into the data base.

    I had already thought about the following struct, but would like to know from you what the best method is.

    Here my struct

    struct Mushroom{
        int id;
        QString fullname;
        QString genus;
        QString kind;
        QString family;
        QString order;
        QStringList germanNames;
        QStringList synonyms;
        QString redlist;
        QString notes;
    };
    

    Thanks for your help
    Gabber

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 20 Oct 2021, 19:44 last edited by
      #2

      Hi,

      You should check QDataWidgetMapper.

      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
      1
      • M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 20 Oct 2021, 20:11 last edited by
        #3

        Hi
        Its a requirement that the data be shown in LineEdits etc ?
        Im asking as Qt can show a table from DB with full edits in just a few lines of code.
        https://doc.qt.io/qt-5/qsqltablemodel.html
        https://doc.qt.io/qt-5/qsqlrelationaltablemodel.html#details

        If yes, it must, then QDataWidgetMapper is the way to go as @SGaist suggests.

        1 Reply Last reply
        1
        • ? Offline
          ? Offline
          A Former User
          wrote on 21 Oct 2021, 17:21 last edited by
          #4

          Thanks for the tip. It works wonderfully with the mapper (at least the display of the content) change and reinsert into the database I still have to implement. If it does not work, I would contact you again if necessary.

          Should I mark the thread as solved or only when I have implemented the change and insert also, in case of possible queries?

          M 1 Reply Last reply 21 Oct 2021, 17:49
          0
          • ? A Former User
            21 Oct 2021, 17:21

            Thanks for the tip. It works wonderfully with the mapper (at least the display of the content) change and reinsert into the database I still have to implement. If it does not work, I would contact you again if necessary.

            Should I mark the thread as solved or only when I have implemented the change and insert also, in case of possible queries?

            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 21 Oct 2021, 17:49 last edited by
            #5

            @Gabber

            Hi
            It's fine to close it and then just open another one in case you got new questions.
            This will keep the posts shorter and easier for newcomers to look at if they search for solutions.

            1 Reply Last reply
            0

            4/5

            21 Oct 2021, 17:21

            • Login

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