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. whether it is possible to call functions using threads without using multi-thread or class threads
Forum Updated to NodeBB v4.3 + New Features

whether it is possible to call functions using threads without using multi-thread or class threads

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 248 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.
  • B Offline
    B Offline
    Blackzero
    wrote on last edited by
    #1

    Is it possible to call a function that contains a process loop and change the label using only one main class without creating multi-threads?
    here is my code example

    void MainWindow::Process()
    {
    	
    	while (2)
    	{
    		if (status)
    		{
    			ui->label->setText("Process..");
    			// my process....
    		}
    		else
    		{
    			ui->label->setText("Process Failed");
    		}
    	}
    
    }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What is that "process" ?

      Note that with your infinite loop you will be blocking Qt's event loop.

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

      B 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        What is that "process" ?

        Note that with your infinite loop you will be blocking Qt's event loop.

        B Offline
        B Offline
        Blackzero
        wrote on last edited by
        #3

        @SGaist said in whether it is possible to call functions using threads without using multi-thread or class threads:

        Apa "proses" itu?

        that's just an example of my original code, but that's part of the other code, but the problem is when I call the function using a regular thread an error occurs "QObject::killTimer: Timers cannot be stopped from another thread" and this is the thread I used to call the Process function

            std::thread thread(&MainWindow::Process, this);
            thread.detach();
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You cannot call GUI related function from a different thread.

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

          B 1 Reply Last reply
          3
          • SGaistS SGaist

            You cannot call GUI related function from a different thread.

            B Offline
            B Offline
            Blackzero
            wrote on last edited by Blackzero
            #5

            @SGaist So you mean I can't call GUI functions in threads not from qt's built-in QThread?

            Christian EhrlicherC JonBJ 2 Replies Last reply
            0
            • B Blackzero

              @SGaist So you mean I can't call GUI functions in threads not from qt's built-in QThread?

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Blackzero said in whether it is possible to call functions using threads without using multi-thread or class threads:

              So you mean I can't call GUI functions in threads not from qt's built-in QThread

              That's exactly what @SGaist wrote.

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

              1 Reply Last reply
              0
              • B Blackzero

                @SGaist So you mean I can't call GUI functions in threads not from qt's built-in QThread?

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #7

                @Blackzero
                It doesn't actually matter whether you use QThread, std::thread or anything else: you are not allowed to directly access any Qt GUI functions/variables etc. from any thread other than the original, main thread of your Qt application. Qt GUI operations are not multithreaded. At best you can send signals from secondary threads which the main thread has put a slot on, so that it is the main thread which accesses the GUI stuff "on behalf of" whatever the secondary thread reports.

                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