SplashScreen stay on TaskManager
-
Oh. that way.
Well you dont have a MainWindow.
QApplication will close application when the last window is closed.
Not sure it knows about QSplashScreen.But when you dont have any mainwindow/top level widgets, it keeps running.
You can make it exit calling quit() but its hard with just a QSplashScreen.
So as you see in tut 28. he does have Mainwindow also ?
-
@mrjj said in SplashScreen stay on TaskManager:
Oh. that way.
Well you dont have a MainWindow.
QApplication will close application when the last window is closed.
Not sure it knows about QSplashScreen.But when you dont have any mainwindow/top level widgets, it keeps running.
You can make it exit calling quit() but its hard with just a QSplashScreen.
So as you see in tut 28. he does have Mainwindow also ?
yes the tutorial have windows application...
but I don't need it..in fact my project is simple,...
I want to make a splashscreen with PNG transparency,..(without windows form)
so I don't know if this is the way to go for it..I want to start with this,..and then,..add features...to be customized,.like time delay, fadein/fadeout, animated PNG etc...
-
@QtA_
Ok, "(without windows form)" means with no borders or caption etc?I think you can use splashscreen for this but not sure its really needed.
Will it be sort of a class others can use , as a super splashscreen thing or
what is the goal ?Well you current issue can be fixed by calling apps quit() when you want the app to exit.
like 2 timers. one call close for splashscreen and other call quit()
but it all depends on how u want it to work. -
@mrjj said in SplashScreen stay on TaskManager:
@QtA_
Ok, "(without windows form)" means with no borders or caption etc?I think you can use splashscreen for this but not sure its really needed.
Will it be sort of a class others can use , as a super splashscreen thing or
what is the goal ?Well you current issue can be fixed by calling apps quit() when you want the app to exit.
like 2 timers. one call close for splashscreen and other call quit()
but it all depends on how u want it to work.that's why I'm here :)
I'm a biginner with C++, so need to understand manything actually.
my english is also not very good, but its ok I think. :)The goal should be something like this:
- create an EXE allowing parameters to show splashscreen.
ex:
mysplash.exe "c:/my images/logo1.png" /d:3 /fi:1 /fo:1wich:
/d = delay
/fi = fade in time delay
/fo = fade out time delaythen,...few version after,...allowing to execute splash with mutliple image running to make an animated splash with PNG files.. :)
-
@mrjj said in SplashScreen stay on TaskManager:
@QtA_
ahh, sort of fancy app loader. :)
well that is a fun project.You english is fine. :)
That should be possible for a first project. Good luck and feel free to ask.
Thank you very much,..
I'm a fancy girl :)return a.quit();
do not close the process,..do I miss something ?
-
@QtA_
Hi
do you now have
return a.exec();
return a.quit();?
it stays inside a.exec().
you can try
QTimer::singleShot(2500,&app,SLOT(quit()));
should kill it all after 2,5 secs.
U must keep return a.exec(); to use timers. Its drives the eventloop :) -
nope,..:( still active.
#include <QApplication> #include <QSplashScreen> #include <QTimer> int main(int argc, char *argv[]) { QApplication a(argc, argv); QSplashScreen *splash=new QSplashScreen; splash->setPixmap(QPixmap ("C:/Users/public/test/Logo.png")); splash->show(); QTimer::singleShot(2500,splash,SLOT(close())); QTimer::singleShot(2500,splash,SLOT(quit())); return a.exec(); return a.quit(); }
-
@QtA_
You are asking it wrongly :)QTimer::singleShot(2500,splash,SLOT(quit())); <<<< wrong object. should be &app
you are asking the timer to call quit() on splash, which splash dont have.
QTimer::singleShot(2500,&app,SLOT(quit()));
Update:
Also
The return statement will make it leave a function
soreturn a.exec();
return a.quit(); <<< u can never, ever get here :) -
Thank you very much !! :)
so i've added:QTimer::singleShot(2500,&a,SLOT(quit()));
and removed
return a.exec();
seem to work fine now :)
Question...
why do I need to put time delay on quit if already the time done ?
I mean,..QTimer::singleShot(2500,&a,SLOT(quit()));
must be
QTimer::singleShot(0,&a,SLOT(quit()));
?
-
You don't need to force the app quit. It's not very flexible in the long run. By default Qt app quits automatically when a last window is closed. This is controlled in two places: on application level with
setQuitOnLastWindowClosed
(the default istrue
, so no need to change that). The other place is at the widget level with an attributeQt::WA_QuitOnClose
. This attribute is by default enabled for top level windows i.e. widgets with flagQt::Window
orQt::Dialog
except for certain types, including menus, tooltips and splashscreen.Since a splashscreen is all you have you can just turn the attribute back on:
int main(int argc, char *argv[]) { QApplication a(argc, argv); QSplashScreen *splash = new QSplashScreen; splash->setAttribute(Qt::WA_QuitOnClose); // <-- the relevant line splash->setPixmap(QPixmap ("C:/Users/public/test/Logo.png")); splash->show(); QTimer::singleShot(2500,splash,SLOT(close())); return a.exec(); }
Btw. Technically this code leaks memory as you never delete the splash instance. To keep it clean you have couple of options:
- manually delete the splash after the call to exec
- add
WA_DeleteOnClose
attribute to the splash - (the easiest and recommended) just create the splash instance on the stack:
QSplashScreen splash; splash.setAttribute(Qt::WA_QuitOnClose); splash.setPixmap(QPixmap ("C:/Users/public/test/Logo.png")); splash.show(); QTimer::singleShot(2500,&splash,SLOT(close()));
-
@Chris-Kawa
Much better with WA_QuitOnClose, indeed. :)Do you know if QSplashScreen can do anything special compared to a plain QWidget in terms
of her overall goal? ( sort of fancy launcher )Im not sure if a custom widget is not more fun later when she wants animations and fade in/out effects etc. Of Course she can derive from QSplashScreen but I do wonder if it
give anything of benefit for this use case. ? -
Thank you guys,,...
it seem to work,..however..many questions in my little brain..
splash name is my variable right ?
so may I redefine it many times ?#include <QApplication> #include <QSplashScreen> #include <QTimer> int main(int argc, char *argv[]) { QApplication a(argc, argv); QSplashScreen *splash = new QSplashScreen; splash->setAttribute(Qt::WA_QuitOnClose); // <-- the relevant line splash->setPixmap(QPixmap ("C:/Users/public/test/Logo.png")); splash->show(); QTimer::singleShot(2500,splash,SLOT(close())); splash->setPixmap(QPixmap ("C:/Users/public/test/Logo1.png")); splash->show(); QTimer::singleShot(2500,splash,SLOT(close())); return a.exec(); }
seem it keep always the last image...
-
@mrjj QSplashScreen is pretty basic. It's not well suited for any sort of animations. The easiest route for that would be, indeed, a plain old widget and overriding its
paintEvent
. Deriving from QSplashScreen would just get in your way.@QtA_ You're thinking in line, while what happens is event driven. This code
QTimer::singleShot(2500,splash,SLOT(close()));
doesn't "wait" for 2.5 seconds. It just schedules the slot to fire in 2.5 seconds and moves on immediately. So this:splash->setPixmap(QPixmap ("C:/Users/public/test/Logo.png")); splash->show(); QTimer::singleShot(2500,splash,SLOT(close())); splash->setPixmap(QPixmap ("C:/Users/public/test/Logo1.png"));
is just the same as this:
splash->setPixmap(QPixmap ("C:/Users/public/test/Logo.png")); splash->setPixmap(QPixmap ("C:/Users/public/test/Logo1.png")); splash->show(); QTimer::singleShot(2500,splash,SLOT(close()));
To make it work like you want to you need to schedule the switch to happen some time later, e.g.
splash->setPixmap(QPixmap ("C:/Users/public/test/Logo.png")); //set initial image QTimer::singleShot(1000, [&]{ splash->setPixmap(QPixmap ("C:/Users/public/test/Logo1.png")); }); //change it after a second QTimer::singleShot(2000, [&]{ splash->setPixmap(QPixmap ("C:/Users/public/test/Logo2.png")); }); //change it again after 2 seconds etc. splash->show(); QTimer::singleShot(2500,splash,SLOT(close()));
-
ok,...that work great !
my PNG animation is now done.. :) thank you.However,..there is few questions if you dont mind.
is the [&] mean to execute what is in the bracket ? {}I understand what i'm doing...but I do not understand yet how, when and why to put sometime bracket, [] sometime <> sometime "" or {}
i'm a little lost on when to use it..
is there any tutorial who explain this syllabus ?
Thanks again for all your help :)