[Solved] How can I show a GUI while working on background
I'm working on Qt5 and I have that in main:
int main(int argc, char *argv)
QApplication a(argc, argv);
MainWindow w; w.showMaximized(); return a.exec();
And then in the constructor I call some functions that will create folders and copy and move files.
MainWindow::MainWindow(QWidget *parent) :
[...] //Code that should work on background
What I want is to show the gui (where you have/see a picture with movement and some other GUI elements such as labels with some text that changes) while the program works on the background but what that code does is to do all the background job and once it has finished, then the GUI appears.
Are you describing what's commonly known as a "splash screen"?
Sorry but it's not. A Splash screen as I have understood, its an image and its used before the app starts or while starting.
What I want isn't that because as I said it will have other elements such as labels or a progressbar... :)
What you are describing is a classic software setup process that should happen before the GUI is shown so Moschops is right, a splash screen is generally used to give the user a visual feedback that there's something happening e.g. device initialization, GUI setup etc.) and once everything is ready, the final GUI is shown.
Then I explained it so bad ^^''
This gui app will occupy all the screen (because it will be called by another app and has to have the same style). So it has some labels with fixed information, a progress bar, an image, some widgets, .., and a label which text will change depending of the background work.
I see splash as a single image to put in the middle of the screen, if possible with alpha like a logo or something like this... maybe I have a wrong idea about it but I hope that now what I have and need is more understanding :D
Then shouldn't you rather show the GUI and a modal QProgressDialog which will be updated by your background initialization stuff ? By background I suppose you mean something in another thread ?
Srry for the late answer but I was busy with other things.
Finally I created a new class which inherited from QThread and created both on main, then put there thread1.myconnectfunction(&thread2) which is the function where I put all the connect() needed so both threads can see each other.
With that I put the GUI on the mainwindow and the background work on my new class.