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. Multi threading with Model View framework?
Forum Updated to NodeBB v4.3 + New Features

Multi threading with Model View framework?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 4.8k 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.
  • CAD_codingC Offline
    CAD_codingC Offline
    CAD_coding
    wrote on last edited by
    #1

    Hi,
    Please forgive me because this is my first application in GUI as such & after reading some suggestions on this forum & the articles I have now understood the concept of Model/View framework.
    But I am unable to implement it in my multi threaded application because I am unable to decide which classes are good for multi threading. Let me tell something about my application:

    Basically I am storing a 2D array of double variables for performing scientific calculations in my application. I was previously using QTableWidget for displaying this data to the user. It was fine till array size was 1000x1000 & single threaded. But when I multi threaded the initialisation of data from reading a file, it gave very bad performance. Hence moving to Model/View framework.
    My usage is:

    Opening the file in each thread, reading data from it & setting it to the GUI. Each thread has a pre-decided set of rows which it initialises. (EX: for 1000x1000, if there are say 4 threads then thread 1 will initialise 1-250, thread 2 will initialise 251 - 500, & so on). So far I am setting the data to a double array along with the table. If I comment out the QTableWidget code then I get a tremendous performance boost. This means that my existing multi threaded code is good & the problem is only when I set the data to QTableWidget & not the double array.

    Any suggestions on how I should implement the Model/View framework?
    Thank You.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You should look into making your own model (QStandardItemModel or QTableModel) and use a QTableView. You are currently loading what seems to be a lot of data then duplicate it in your QTableWidget which will impact on your performance.

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • CAD_codingC Offline
        CAD_codingC Offline
        CAD_coding
        wrote on last edited by
        #3

        Hi SGaist,
        Can I add data to QStandardItemModel from multiple threads simultaneously?
        If yes then is it fine if I keep a pointer to the model in each thread & then add data to it from each thread?

        Also I think the QTableView should be in the GUI thread, but what about the QStandardItemModel? Is it ok to keep it in different thread without affecting performance?

        1 Reply Last reply
        0
        • JKSHJ Online
          JKSHJ Online
          JKSH
          Moderators
          wrote on last edited by
          #4

          Hi,

          All QObjects (including QStandardItemModel) are not thread-safe, so you cannot write to them simultaneously from multiple threads. Each object must only be accessed from one thread.

          Keep your QStandardItemModel in the GUI thread, and implement a slot to update its data. When each thread has finished initializing the data, emit a signal to tell the slot to update the QStandardItemModel.

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0

          • Login

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