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. From CSV file to QSpinBox
Forum Update on Monday, May 27th 2025

From CSV file to QSpinBox

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 387 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.
  • A Offline
    A Offline
    aim0d
    wrote on 7 Sept 2022, 07:46 last edited by aim0d 9 Jul 2022, 07:50
    #1

    Hi!
    I'm totally new to Qt Creator and I tried looking only but as a newbie I feeling very lost.
    I have a table format in CSV file with several datas (like how many house are in the city, how many of them use elettricity) and I would like to insert these value in different QSpinBox I added via mainwindow.ui .
    How can I do it?
    I saw there are some functions like QStringClass, but also by looking at the documentation HERE I dont get it.
    Online I also found an example (in russian and couldnt remember from where) but it's traslate all the file literally and it's not like I need it.

    If someone could explain it to me it would be an huge favor.

    (I didnt know which categories was suitable, sorry if it's the wrong one)

    J 1 Reply Last reply 7 Sept 2022, 07:50
    0
    • A aim0d
      7 Sept 2022, 07:46

      Hi!
      I'm totally new to Qt Creator and I tried looking only but as a newbie I feeling very lost.
      I have a table format in CSV file with several datas (like how many house are in the city, how many of them use elettricity) and I would like to insert these value in different QSpinBox I added via mainwindow.ui .
      How can I do it?
      I saw there are some functions like QStringClass, but also by looking at the documentation HERE I dont get it.
      Online I also found an example (in russian and couldnt remember from where) but it's traslate all the file literally and it's not like I need it.

      If someone could explain it to me it would be an huge favor.

      (I didnt know which categories was suitable, sorry if it's the wrong one)

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 7 Sept 2022, 07:50 last edited by jsulm 9 Jul 2022, 07:51
      #2

      @aim0d

      • Read the CSV file line by line using QFile (https://doc.qt.io/qt-6/qiodevice.html#readLine-1)
      • Split each line using https://doc.qt.io/qt-6/qstring.html#split-1
      • Then you have a QStringList where each entry is from a column of your file. You should know which column should be used for which QSpinBox
      • Convert the strings to int to put them into QSpinBox using https://doc.qt.io/qt-6/qstring.html#toInt

      If something is not clear then please ask concrete questions ("I dont get it" - is not a question or problem description).

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply 7 Sept 2022, 08:37
      1
      • J jsulm
        7 Sept 2022, 07:50

        @aim0d

        • Read the CSV file line by line using QFile (https://doc.qt.io/qt-6/qiodevice.html#readLine-1)
        • Split each line using https://doc.qt.io/qt-6/qstring.html#split-1
        • Then you have a QStringList where each entry is from a column of your file. You should know which column should be used for which QSpinBox
        • Convert the strings to int to put them into QSpinBox using https://doc.qt.io/qt-6/qstring.html#toInt

        If something is not clear then please ask concrete questions ("I dont get it" - is not a question or problem description).

        A Offline
        A Offline
        aim0d
        wrote on 7 Sept 2022, 08:37 last edited by
        #3

        @jsulm I simply dont understand how to implement code; I tried using QFile like the first example here with my csv translated in txt file;
        But it gives me this errors:
        6e5ba321-af9d-491d-8e5d-0d7905eab284-error.png

        Maybe it's stupid that I'm having problem with this; but I'm new and started yesterday watching this kind of stuff

        J J 2 Replies Last reply 7 Sept 2022, 08:40
        0
        • A aim0d
          7 Sept 2022, 08:37

          @jsulm I simply dont understand how to implement code; I tried using QFile like the first example here with my csv translated in txt file;
          But it gives me this errors:
          6e5ba321-af9d-491d-8e5d-0d7905eab284-error.png

          Maybe it's stupid that I'm having problem with this; but I'm new and started yesterday watching this kind of stuff

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 7 Sept 2022, 08:40 last edited by
          #4

          @aim0d Isn't the first error self-explanatory? main() returns an int, you have a return statement without returning an int --> C++ basics.
          Where is your process_line declared?

          Also, you're using a relative path to your file - this will not work unless the file is in current working directory.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          3
          • A aim0d
            7 Sept 2022, 08:37

            @jsulm I simply dont understand how to implement code; I tried using QFile like the first example here with my csv translated in txt file;
            But it gives me this errors:
            6e5ba321-af9d-491d-8e5d-0d7905eab284-error.png

            Maybe it's stupid that I'm having problem with this; but I'm new and started yesterday watching this kind of stuff

            J Online
            J Online
            JonB
            wrote on 7 Sept 2022, 08:56 last edited by
            #5

            @aim0d
            Further to @jsulm. You are starting to write code after main()s' (unconditional) return a.exec(); statement, which cannot be correct.

            I don't see Qt issues here. If you were not using Qt would you know how to write the code you want? If so it's not that different using Qt. If not it's C++ or algorithmic issues.

            A 1 Reply Last reply 8 Sept 2022, 06:33
            2
            • J JonB
              7 Sept 2022, 08:56

              @aim0d
              Further to @jsulm. You are starting to write code after main()s' (unconditional) return a.exec(); statement, which cannot be correct.

              I don't see Qt issues here. If you were not using Qt would you know how to write the code you want? If so it's not that different using Qt. If not it's C++ or algorithmic issues.

              A Offline
              A Offline
              aim0d
              wrote on 8 Sept 2022, 06:33 last edited by aim0d 9 Aug 2022, 06:34
              #6

              @JonB I was also having trouble understand C++; new to that one too.
              But I found a tutorial on YT and kinda find the result I was looking for.

              (I'm gonna link the YT video, if I can and if someone will have the same problem as me in the future)

              1 Reply Last reply
              1

              1/6

              7 Sept 2022, 07:46

              • Login

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