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. How make a program interface asynchronous with the program logic execution?
Forum Updated to NodeBB v4.3 + New Features

How make a program interface asynchronous with the program logic execution?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 445 Views
  • 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.
  • G Offline
    G Offline
    gyok
    wrote on last edited by
    #1

    I have a program which go through QTableWidget cells (left&right) and change symbols in them. Execution starts when I press "run" button, but when program executing I can't see intermediate result, only finish result. If I trying resize program interface it freezing. Already trying to avoid this problem with running program logic with concurrent function:

    int Run() {
        QFuture<int> future = QtConcurrent::run(this, &Core::run);
        return 0;
    }
    
    int Core::run () {
        while (i < 5) {
            i++;
            execute();
            mainwindow.update();
            _table.update();
        }
        return 0;
    }
    
    int Core::execute() {
        // move right in table
        _table.item(0, _current++)->background() = Qt::yellow;
        return 0;
    }
    

    But this not working. Should I try emit signals for execute() function to change colour of table cells, or how you remove freezing of program interface?

    aha_1980A 1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @gyok said in How make a program interface asynchronous with the program logic execution?:

      _table.item(0, _current++)->background() = Qt::yellow;

      If _table is a QTableWidget I doubt this will ever compile.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      G 1 Reply Last reply
      0
      • G gyok

        I have a program which go through QTableWidget cells (left&right) and change symbols in them. Execution starts when I press "run" button, but when program executing I can't see intermediate result, only finish result. If I trying resize program interface it freezing. Already trying to avoid this problem with running program logic with concurrent function:

        int Run() {
            QFuture<int> future = QtConcurrent::run(this, &Core::run);
            return 0;
        }
        
        int Core::run () {
            while (i < 5) {
                i++;
                execute();
                mainwindow.update();
                _table.update();
            }
            return 0;
        }
        
        int Core::execute() {
            // move right in table
            _table.item(0, _current++)->background() = Qt::yellow;
            return 0;
        }
        

        But this not working. Should I try emit signals for execute() function to change colour of table cells, or how you remove freezing of program interface?

        aha_1980A Offline
        aha_1980A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @gyok the simplest way is to use a QTimer instead a loop. in the timeout slot, process one or a few cells, then exit the slot. that gives Qt the chance to refresh your GUI before you process the next elements.

        Regards

        Qt has to stay free or it will die.

        1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          @gyok said in How make a program interface asynchronous with the program logic execution?:

          _table.item(0, _current++)->background() = Qt::yellow;

          If _table is a QTableWidget I doubt this will ever compile.

          G Offline
          G Offline
          gyok
          wrote on last edited by
          #4

          @Christian-Ehrlicher I add this exemple of code to show the main idea of code

          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