From CSV file to QSpinBox
-
wrote on 7 Sept 2022, 07:46 last edited by aim0d 9 Jul 2022, 07:50
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)
-
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)
Lifetime Qt Championwrote on 7 Sept 2022, 07:50 last edited by jsulm 9 Jul 2022, 07:51- 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).
-
- 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).
wrote on 7 Sept 2022, 08:37 last edited by -
@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.
-
wrote on 7 Sept 2022, 08:56 last edited by
@aim0d
Further to @jsulm. You are starting to write code aftermain()
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.
-
@aim0d
Further to @jsulm. You are starting to write code aftermain()
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.
wrote on 8 Sept 2022, 06:33 last edited by aim0d 9 Aug 2022, 06:34
1/6