How to let qtimer execute if under while loop
-
I think @SGaist meant the 'long calculation' part of your program in a separate thread.
The GUI should not be split into different threads (including the openGl parts). I am not ever sure if you can actually have Qt GUI elements run in different threads (like QWidget). If this is possible you should avoid it. Threads should be used for long calculations or other non-GUI functions.
If the openGl part is slow you should look into some method to pre-process your vertex data (display lists or the modern equivalent) to take some of the weight of the render function.
-
Opengl get slow if lot of data and drawing but no need for too much, wont fit on monitor anyway.
Then will start to learn threading for worker part ,
Gui can be main thread but nice if gl also seperate then gui not connected to gl fps drops.
-
@Rondog is right about what I meant.
QWidget can not be manipulated outside the GUI thread.
In what case are you experiencing OpenGL slow-down ? Before trying to put everything in different threads you should analyze what you are doing in OpenGL, how are you feeding data to the GPU etc.
-
Data to gpu is from ram generated to triangles , 2 triangles 1 line .
If over 50 000 lines cpu get slow feeding and calculating for gpu , also ui refreshg rate drops but it no problem in normal operation .
By taking calculating part away to seperate thread probably good enough to lose problems with gui refresh.If have time please answer few threading questions.
If have created thread and try start it in main function by
Calc_thread t_obj;
t_obj.start();
Is should have ran as with while(1) loop cpu rised.this is thread .h file
#ifndef CALC_THREAD_H
#define CALC_THREAD_H#include <QtCore>
class Calc_thread : public QThread
{
public:
Calc_thread();void run();
};
class Calc_Class
{
public:
void graph_code_run();
....etcHow could voids in Calc_Class be accessed on seperate thread if it is created once in main function?
Or have to put all functions under Calc_thread class? -
Are you sure you're doing the jobs at the right places ? Generating everything with your CPU and then just use the GPU to show the result isn't the most efficient way to do things
-
@SGaist Data comes from vector containers that are loaded from disk, not sure how to make program more efficient.
Not sure how to acess other class under other thread, should it be named to same class as thread to acess it? -
Do you read them once from the disk ?
-
@SGaist Yes , Once to ram to vectors further from ram.
-
What do you mean by "to vectors further from ram" ?
-
@SGaist
From disk is loaded to vector containers in ram , then further from vectors for graph generation or for testing that takes calculating power.
Now it running seperate thread and in comparison to runnignsame thread as gui and opengl about 5% faster without forced gui refresh.
No need put opengl seperate thread , it works well together with gui thread.