logo
Tags down

shadow

Should I call processEvents() on a thread?


By : user6095759
Date : September 17 2020, 05:00 AM
this will help your run() function 'blocks' the thread. It is being invoked in the thread context, but never returns. This means, the event loop in the thread doesn't get executed anymore as soon as your run() funtion is called.
For the timer events to call your lambdas, the event loop has to be processed. If you would modify your run function like this:
code :
void run() {
    timer = new QTimer(this);
    connect(timer, &QTimer::timeout, []{qDebug() << "computed";});
    timer->start(1000);

    // don't loop here, instead exit the function 
    // and let the thread return back to the event loop
}
connect(&thread, &QThread::started, worker, &Worker::run);
thread.start();


Share : facebook icon twitter icon

Should I use QCoreApplication::processEvents() or QApplication::processEvents()?


By : Jayashree Mani
Date : March 29 2020, 07:55 AM
wish helps you Neither, processEvent() should be calld only when you have actual pending events to process. You may find this useful : How to make Qt work when main thread is busy?

Proper thread call syntax? error: no matching call to std::thread::thread(<brace-enclosed initializer list>)


By : Ashutosh
Date : March 29 2020, 07:55 AM
This might help you You need to pass a function to the constructor of thread. In your code, you are calling r.check() and passing the result to the constructor of thread, and a constructor which takes such an argument does not exist, hence the error.
The thread constructor takes a function and arguments. And in the case of a member function, the first argument is the this pointer. So for your code you need:
code :
thread rt0 { &RowChecker::check, &r0 };

QCoreApplication::processEvents - why must it be called from main thread only?


By : user3327329
Date : March 29 2020, 07:55 AM
Hope that helps Your title is not true. Probably you are assuming QCoreApplication::processEvents is a system-wide "process all possible events of all threads" call, which it is not. You can call it from any thread you are in (and which is running an event loop).
Why does it matter from which thread it is called: In Qt the event loop is a per-thread resource (you can run own event loop on any thread) and QCoreApplication::processEvents processes event queue of the current thread.

C# Basic Multi-Threading Question: Call Method on Thread A from Thread B (Thread B started from Thread A)


By : ran levi
Date : March 29 2020, 07:55 AM
I wish did fix the issue. Typically, this is unnecessary. You can call a method on any object from any thread, and this is a good thing... UI components and some legacy COM components tend to be the only items which must be accessed from a specific thread.
Instead of trying to call a method on a different thread, normally, you'll try to use synchronization (ie: lock(...) and similar) to protect access to the data itself, and make it safe to work with from multiple threads.

QApplication::processEvents on a different thread


By : Adele Sayehafkan
Date : March 29 2020, 07:55 AM
I wish did fix the issue.
It may be possible but Qt is not tested for it. I imagine that it's possible to hack that in - you'd need code changes. It won't ever work on MacOS, unless you're having only QCoreApplication in mind - neither the QApp.. nor QGuiApp.. supports other threads on that platform, and possibly on other platforms as well (Windows excepted). I have no idea why would you do that, though. Once the QApplication event loop is running on the given thread, it can terminate on command and automatically destroy the application instance. In fact, it's trivial:
code :
int main(int argc, char *argv[]) {
  QScopedPointer<QCoreApplication> app(new QCoreApplication(argc, argv));
  QtConcurrent::run([]{
    // this runs in a worker thread, and causes the application
    // object to destroy itself and then the program to exit
    QThread::sleep(2);
    QCoreApplication::quit();
  });
  auto rc = app.exec();
  app.reset();
  // perhaps do some other processing here that doesn't need
  // a qApp instance
  return rc;
}
Related Posts Related Posts :
  • Averaging ADC readings have strange steps in plot
  • Rock,Paper, Scissors Program Game
  • Why pow(10,2)=99 & pow(10,3)=1000?
  • What is the lifetime of C++ member variables when running in a std::thread?
  • C++ | Print tree (not necessarily binary) in a pretty way to stdout
  • The difference between delete and the destructor when both called?
  • What happens inside of a C++ constructor?
  • Mixing overriding and overloading in C++
  • Is std::stringstream::flush() supposed to do anything?
  • How does Qt::DirectConnection act when used in multi-threaded environment?
  • bison/flex: calculator interprets double values as integers so I added #define YYSTYPE double, but I multiple compilatio
  • Register the environment varibles for TBB
  • modelo of square is zero, factorial modelo problem
  • Split student list that has format like: 0001 William Bill Junior 8.5
  • How to use the overloaded "operator<<" properly?
  • Why Smart pointers can not be declared the usual Pointer way
  • I can't figure out what is wrong my implementation of MST with Kruskal algorithm
  • C++ how would one simplify this template so that it is not specialized?
  • What happens when a reference of an object (with different types) is deleted?
  • Is main() always on the stack?
  • What if one process in a MPI program proceeds more slowly than others?
  • I'm trying to get current date and time in cpp but can't understand these lines
  • make_pair() in C++
  • How can I access to derived members from a pure virtual base class function?
  • Constructor cannot be redeclared. Why?
  • Is there any similar function to glibc mtrace() function in c++?
  • faster erase-remove idiom when I don't care about order and don't have duplicates?
  • How to store variable as nothing
  • How to properly free a set of pointers?
  • C++ file IO - ASCII value instead of Binary value
  • Weird behavior of a simple for-loop code using "find" function in C++(to increment value if a certain sub-stri
  • I want two loops to run in parallel
  • Why would it be good to use dynamic memory allocation with serial communication?
  • non static member in static cpp
  • Non type template parameter
  • 3x3 Matrix Rotation with non uniform scaling
  • what actually sets the _WIN32 or _WIN64 preprocessor?
  • How to return a type from C++ functions?
  • c++ *& and null validation
  • Difference between Array, Vector and Matrix in C++?
  • Unable to enter while loop:"Segmentation fault"
  • Modify value const method
  • Unable to compile with Error C2440 due to type cast from C to C++
  • I try to understand what pointer variable is changing after xor operation
  • When declaring a pointer, VS automatically moves the asterisk to the pointer's type
  • static member declared const but initialized as constexpr
  • How to obtain the URL of re-directed webpage in C++
  • I need to change the main program, because I want input from the user how can I do it?
  • How to create a POST request with wininet in C++
  • How "lock add" is implemented on x86 processors
  • c++ assigment operator with two or more template arguments
  • Problem with compiling a mingw32 executable on linux system with boost.asio
  • Why is the ENTRY() in my linker script not being set to the . = <address> section?
  • Why is min_element() returning the index of the minimum element, instead of an iterator?
  • Can priority queue be made by using simple queues
  • How to improve vector insert time
  • OpenGL integer texture raising GL_INVALID_VALUE
  • better method rather than using cin.ignore in c++
  • C++ A function that can return one of two types depending on the accepted value
  • How can i declare object in an if statement and use it wherever i want?
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk