0

Application: The purposed application has an tcp server able to handle several connections with the robots. I choosed to work with database/ no files, so i'm using a sqlite db to save information about the robots and their full history, models of robots, tasks, etc... The robots send us several data like odometry, tasks information, and so on...

I create a thread for every new robot's connection to handle the messages and update the informations of the robots on the database. Now lets start talk about my problems:

The application got to show information about the robots in realtime, and I was thinking about using QSqlQueryModel, set the right query and the show it on a QTableView but then I got to some problems/ solutions to think about:

Problem number 1: There are informations to show on the QTableView that are not on the database: I have the current consumption on the database and the actual charge on the database in capacity, but I want to show also on my table the remaining battery time, how can I add that column with the right behaviour (math implemented) in my TableView.

Problem number 2: I will be receiving messages each second for each robot, so, updating the db and the the gui(loading the query) may not be the best solution when I have a big number of robots connected? Is it better to update the table, and only update the db each minute or something like this? If I use this method I cant work with the table with the QSqlQueryModel to update the tables, so what is the approach that you recommend me to use?

Thanks SancheZ

  • Can you show us what code you have tried so far so we can fix it for you? – mike510a Apr 29 '17 at 09:25
  • I have the server module, the connections thread, the db setup and some windows done, but I am only starting to design how I'm going to implement the tables behaviour on GUI, and I dont know how can I do it... – João Sanchez Apr 29 '17 at 13:49

1 Answers1

0
  1. I have run into similar problem before; my conclusion was QSqlQueryModel is not the best option for display purposes. You may want some processing on query results, or you may want to create, remove, change display data based on the result for a fancier gui. I think best is to implement your own delegates and override the view related methods - setData, setEditor

This way you have the control over all your columns and direct union of raw data and its display equivalent (i.e. EditData, UserData).

  1. Yes, it is better if you update your view real-time and run a batch execute at lower frequency to update the big data. In general app is the middle layer and db is a bottom layer for data monitoring, unless you use db in memory shared cache.

EDIT: One important point, you cannot run updates in multiple threads (you can, but sqlite blocks the thread until it gets the lock) so it is best to run update from a single thread

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
baci
  • 2,528
  • 15
  • 28
  • Thanks man. I am new at qt also, but I got this big project to implement and I dont know all the structures available to work with. So what structures do you recommend me to search for the table's behaviour you are talking about? I was trying to run on multiple threads and was thinking that when I need to implement a query in a thread use mutex, and the same to refresh the main window table elements. It would not work? – João Sanchez Apr 29 '17 at 14:21
  • well you can go through qt examples "spin box delegate" and "star view delegate". you will get an understanding how model/view architecture works. – baci Apr 29 '17 at 14:28
  • One more time thanks man. Just one more thing, the number of rows of my table depends on the number of connected robots. So it will vary along the time. To update the row I want I need to know the correct index were the informaton of that robot is. Is there anyway of setting an ID or something for a row instead of working with its indexs that will vary every time a robot is disconnected? – João Sanchez Apr 30 '17 at 13:43
  • you can create your model with the id field, hide that column for display. straightforward – baci May 01 '17 at 20:05