[SOLVED] What would be the best way to display a list of items in Qt
-
Hi,
I need some advice here, I was wondering what would be the best way to create a list of items. What I have is a list of items that I'm loading in a .txt file using QFile and everything is working fine but I was wondering if this would be easier using something like QListWidget or something like that, since I will be adding and removing items from the list, they also need to be in groups something like...
Group 1
item 1
item 2
item 3Group 2
item 1
item 2
item 3The problem with the method I'm currently using is that I can append new lines but I cannot add them to a certain group, they appear at the end of the file and also deleting items may be challenging (I haven't try deleting yet).
What would be the best way to manage lists of items like the one I'm describing above where new items may be added and deleted?
Thanks
-
If you have a grouping, then you do no longer have a list of items. You might want to use a tree model to represent this.
-
Well, to be using the QFile for deleting or replacing code in the middle of a group is nearly impossible. It can be done, but you have to write lots of code to get all data from the file, change the stuff you want and rewrite it to file. Just think about what you otherwise ask the OS to do. The OS should just delete some stuff in the middle of the file, making that piece available for other apps?!? Of adding a line, simple shift it all?? Not really possible. What you might need is a QTextEdit box. The QTextEdit will handle all modifications you need and when the job is done and the save button is clicked you can write it away to a QFile.
Hope this helps.
the QTreeWidget mentioned by Tobias is also a great representation of list. Not really sure what you need by the way.
Greetz and have fun coding! -
No OS (or file system, really) I know off supports inserting or removing stuff in the middle of files. Appending: yes, but that's a simple operation. Other file modifications (ok, except replacements with the same size of the original) require you re-write the file, at least from the point of the first modification.
Unless you're talking about huge files, this should not be an issue though.
-
Thank you all for the good information, every time I ask a question I learn something else, that's great.
I forgot to mention one thing and probably the most important one is that this file will need to be access by multiple users, in other words any user can modify the file (file will be in a share drive). The list will contain about 150 different material types something like...
STAINLESS STEEL:
Part# Description
Part# Description
Part# Description
...COLD ROLLED STEEL:
Part# Description
Part# Description
Part# Description
...bq. The QTextEdit will handle all modifications you need and when the job is done and the save button is clicked you can write it away to a QFile.
I guess this is the easiest solution, edit the file in a QTextEdit and save it again.
I would love to be able to use something like the QTreeWidget it would look awesome. Can the information hold by QTreeWidget be loaded from an external file?
Should I be using a database instead?
Thanks
-
-
Again: it doesn't solve your issue, so perhaps you should try to solve one issue at a time and not confuse yourself with adding yet more new technologies you'll need to learn.
Anyway, more on using SQL in qt can be found my reading the documentation that appears if you enter "qsql" as the filter for the documentation index in creator. Start with reading the [[doc:QSqlDatabase]] docs.
-
bq. So you want to read and write data from different workstations and keep the data consistent ?
Yes.
bq. I would suggest that before you think about how to display the data, you should think about how you want to achieve the task of the interaction.
Well I'm actually more concern about the interaction than the display part, I just need advice from the experts to find the best solution.
Thanks
-
I'd build a data structure that properly describes what I'm dealing with, and provides a sane API to manipulate it in the ways I need.
What worries me is this sentence:
[quote author="fs_tigre" date="1343216153"]I forgot to mention one thing and probably the most important one is that this file will need to be access by multiple users, in other words any user can modify the file (file will be in a share drive).[/quote]
Does this mean that you'll be doing live updates with multiple users on the same data, and that you expect the data to be updated for all users at that moment? Because that is going to be quite tricky to do, and is not something you can explain how to do in a simple way. -
My first thought was to have a server that reads the initial (text, xml, JSON,..) document into an custom datastructure and maintains its state. The workstations would then access the data (for read and write operations) via an interface (CORBA, WebService, TCP,...) provided by the server.
-
Ok, it looks like this is a complicated task which I'm not prepared for yet.
So far the best solution I think is to use the QTextEdit, load the .txt file, change as needed and save it again.
Last question, if I go with the QTextEdit I'm describing here, what would be the best way to style the content in the .txt file? Do I need to work with an HTML file instead?
Side note: I'm very proficient in HTML and CSS.
Thanks
-
150 people, all editing the same file containing data? That sounds like a job for a database...
-
Still sounds like you want a database to me:-)