D
D
Daniil Chashkov2018-06-02 19:48:27
Python
Daniil Chashkov, 2018-06-02 19:48:27

How to update data in the application without exiting it?

Hello.
Suppose I have a file that contains a list of products (each line has its own product)
And I displayed this list using QVBoxLayout and QLabel.
And I have an add button. And when a product is added, the content of the file is updated.
But the list in the application has not changed, so here's how to make the list in the application change so that you do not have to exit and enter the application again?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2018-06-02
@imnotwhoexpect

You need to write code that updates the GUI components.

P
Philip Bondarev, 2018-06-02
@Dogrtt

In general, there are many ways here (who, his mother, doubted that this is programming ...). I would create an additional class in a separate thread that would check the hash sum of the file at a certain frequency . A change in the amount will mean that something has been added to the file. At this moment, a signal is sent from the watcher thread to the slot of the main gui thread that it would be necessary to refill the table. You can write not just to a file, but let's say in a sqlite3 database (essentially also a regular file), then you can use QListView with QSqlTableModel to display elements (this model, by the way, allows you to write directly to the database, QSqlQueryModelit doesn’t know how out of the box, you need to implement the recording method yourself). By the way, if you yourself add something to the file, then at the time of adding, just give a signal that you need to read the last line or where you add it ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question