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 Updated to NodeBB v4.3 + New Features

From CSV file to QSpinBox

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 390 Views 1 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.
  • A Offline
    A Offline
    aim0d
    wrote on last edited by aim0d
    #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)

    jsulmJ 1 Reply Last reply
    0
    • A aim0d

      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)

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #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
      1
      • jsulmJ jsulm

        @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 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

        jsulmJ JonBJ 2 Replies Last reply
        0
        • A aim0d

          @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

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on 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

            @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

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on 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
            2
            • JonBJ JonB

              @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 last edited by aim0d
              #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

              • Login

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