PDA

View Full Version : Problem with Splash Screen ?



vinod
22nd April 2006, 15:43
Hello,

Here is my code. I am trying to display the "Logo" image as a splash screen on top all of my windows. But when executing , the splash screen is displayed on bottom of the main widget. What is the reason ? How can I solve it ?


#include <qapplication.h>
#include "welform.h"
#include <qtimer.h>
#include <qpixmap.h>
#include <qsplashscreen.h>


int main( int argc, char ** argv )
{


QSplashScreen *splash=NULL;
QApplication a( argc, argv );
welForm *w;


QPixmap logo(QPixmap::fromMimeSource("Logo"));
splash=new QSplashScreen(logo,Qt::WStyle_StaysOnTop|Qt::WX11B ypassWM);
splash->show();
QTimer::singleShot(5*1000,splash,SLOT(close()));

w=new welForm(0,"welForm");
a.setMainWidget(w);
w->show();

//delete splash;
//a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
int rc=a.exec();

//splash->finish(w); this finish() also not work.... so I commented it.
if(splash)
delete splash;

return rc;
}


thanks in advance............

A S Vinod

wysota
22nd April 2006, 16:28
Try this:

QApplication app(argc, argv);
QSplashScreen *splashscreen = new QSplashScreen(QPixmap::fromMimeSource("Logo"), Qt::WDestructiveClose|Qt::WStyle_StaysOnTop); // no need for other flags
splashscreen->show();
app.processEvents(); // this should make the splash appear
welForm *w = new welForm(0,"welForm");
app.setMainWidget(w);
w->show();
QTimer::singleShot(5000,splashscreen,SLOT(close()) ); // timer needs the event queue
return app.exec();

vinod
24th April 2006, 08:14
Hello,

I had tried your code. But the result was same. The splash screen always appeared below to the main window.


So what will be he exact problem....


Vinod

wysota
24th April 2006, 10:08
Did you pass any window flags to the main window?

vinod
24th April 2006, 11:09
No , I didn't pass any arguments to main window...

But , now I solve the problem.

By just calling the finish(mainWindow) function of SplashScreen class before calling show(mainWindow).

Here is the working code :-


int main( int argc, char ** argv )
{

QApplication a( argc, argv );


QSplashScreen *splash=new
QSplashScreen(QPixmap::fromMimeSource("Logo"),Qt::WDestructiveClose|Qt::WStyle_StaysOnTop);
splash->show();
a.processEvents();
welForm *w=new welForm(0,"welForm");
a.setMainWidget(w);
splash->finish(w);
w->show();

QTimer::singleShot(10000,splash,SLOT(close()));
return a.exec();
}



Thank You...

yabadabadoo
7th March 2007, 08:51
hello...
i am trying to display a splash screen before my application starts. But it is not displaying SplashScreen. given below is my code.


#include <QApplication>

#include "client.h"

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QPixmap pixmap("redcross.png");
QSplashScreen *splash = new QSplashScreen(pixmap);
splash->show();
app.processEvents();
splash->showMessage("Loaded modules");

client client;//inherited from QDialog
splash->finish(&client);
client.show();

QTimer::singleShot(5000,splash,SLOT(close())); // timer needs the event queue

return app.exec();
}

thanx

wysota
7th March 2007, 10:51
I tested the code and it worked for me. Maybe the problem is that you use a relative path to the redcross.png image? If QSplashScreen can't find it, it won't be displayed.

yabadabadoo
7th March 2007, 10:57
yes.... that was the problem... thank you very much..

Prashant Kumar
19th January 2019, 18:51
can i use finish before calling show() on the mainwindow?

anda_skoa
26th January 2019, 10:13
can i use finish before calling show() on the mainwindow?

That is what the code in post #6 does, isn't it?.

Cheers,
_

kachhadiyatushar
10th April 2020, 19:02
Hello,

I am running QSplashscreen over my Qt application. I am setting five different images on each second with numeric data. After running few hours it just shows me a black popup without image. The pixmap loading images and setting on splash but, It shows me black screen for 5 seconds. If you guys have any solution for this issue, kindly help me.

Thanks

Tushar

d_stranz
10th April 2020, 23:48
Don't hijack old threads for a new post, please.

My crystal ball is at work, so I can't use it. And without my crystal ball, I can't see the invisible code you have posted to show what you are doing. And since I can't see the invisible code, I can't give you any suggestions for what might be wrong, but I have a pretty good idea. Sorry.

kachhadiyatushar
11th April 2020, 08:30
#ifndef TIMER_H
#define TIMER_H

#include <QTimer>
#include <QDebug>
#include <QSplashScreen>
#include <QPixmap>
#include <QPainter>

class timer_s: public QTimer
{
Q_OBJECT

public:
int timePassed;
QSplashScreen *splash;
float temp;
QFont splashfont;
QString tem,Con_tem,TClock,Snap_Smiley_Image_Path;
QByteArray ab,Con_ab;
QByteArray ba;
int i1,i2;
const char* mychar;
const char* Conv_char;
float a, b;
Qt::Alignment align,align2;
float LowtempC,HightempC;
float HightempF,LowtempF,DisableRedC;
QPixmap InitImage;
QPainter painter;

explicit timer_s(QObject *parent = 0) : QTimer(parent)
{
splash = new QSplashScreen();
}

private slots:

void tick()
{
if(timePassed == 8)
splash->show();
if(timePassed == 0)
{
splash->close();
splash->deleteLater();
stop();
deleteLater();
}
else
{
InitImage.load(""+Snap_Smiley_Image_Path+QString("/timer-%1.png").arg(timePassed)+"");
splash->setPixmap(InitImage);
timePassed--;
}
}

void CelsToF()//F temp to C
{
if((TClock == "false" && timePassed == 5) || (TClock == "true" && timePassed == 2))
{
splashfont.setFamily("Helvetica Neue Regular");
splashfont.setPixelSize(110);
DisableRedC = HightempC;
i1 = tem.count();
ab = tem.toLatin1().insert(i1,"°C");
align = Qt::AlignVCenter|Qt::AlignRight;
mychar = ab.data();
Con_tem = QString::number(temp);
i2 = Con_tem.count();
Con_ab = Con_tem.toLatin1().insert(i2,"°F");
align2 = Qt::AlignVCenter|Qt::AlignRight;
Conv_char = Con_ab.data();//Convert C to F End
splash->show();
}
if(timePassed == 0)
{
splash->close();
splash->deleteLater();
tem.clear();
HightempC = 0;
LowtempC = 0;
a = 0;
b = 0;
stop();
memset(&Conv_char, 0, sizeof(Conv_char));
memset(&mychar, 0, sizeof(mychar));
deleteLater();
}
if(tem.toFloat() >= HightempC && DisableRedC != -999 && timePassed != 0)
{
if(timePassed == 5 || (TClock == "true" && timePassed == 2)){
splash->showMessage(tr(mychar),align,Qt::white);
splash->setFont(splashfont);
}
if(TClock == "true" && (timePassed == 2 || timePassed == 1))
InitImage.load(""+Snap_Smiley_Image_Path+QString("/high%1.png").arg(timePassed)+"");
else
InitImage.load(""+Snap_Smiley_Image_Path+QString("/high%1.png").arg(timePassed)+"");
painter.begin(&InitImage);//Display Other Temp on Top Right Start
painter.setPen(Qt::white);
painter.setFont(QFont("Helvetica Neue Regular",22));
painter.drawText(InitImage.rect(),Qt::AlignTop|Qt: :AlignRight,Conv_char);//Display Other Temp on Top Right end
painter.end();
splash->setPixmap(InitImage);
}
else if(tem.toFloat() <= LowtempC && DisableRedC != -999 && timePassed != 0)
{
InitImage.load(""+Snap_Smiley_Image_Path+QString("/invalid%1.png").arg(timePassed)+"");
splash->setPixmap(InitImage);
}
else
{
if(timePassed == 5 || (TClock == "true" && timePassed == 2)){
splash->showMessage(tr(mychar),align,Qt::white);
splash->setFont(splashfont);
}
if(timePassed != 0)
{
if(TClock == "true" && (timePassed == 2 || timePassed == 1))
InitImage.load(""+Snap_Smiley_Image_Path+QString("/valid%1.png").arg(timePassed)+"");
else
InitImage.load(""+Snap_Smiley_Image_Path+QString("/valid%1.png").arg(timePassed)+"");
painter.begin(&InitImage);//Display Other Temp on Top Right Start
painter.setPen(Qt::white);
painter.setFont(QFont("Helvetica Neue Regular",22));
painter.drawText(InitImage.rect(),Qt::AlignTop|Qt: :AlignRight,Conv_char);//Display Other Temp on Top Right end
painter.end();
splash->setPixmap(InitImage);
}
}
timePassed--;
}

void validtemp()
{
if((TClock == "false" && timePassed == 5) || (TClock == "true" && timePassed == 2))
{
splashfont.setFamily("Helvetica Neue Regular");
splashfont.setPixelSize(110);
//splashfont.setBold(true);
//tem = QString::number(temp);
tem = QString::number(temp,'f',1/*floor(b*10.0)/10.0*/);
i1 = tem.count();
ab = tem.toLatin1().insert(i1,"°F");
align = Qt::AlignVCenter|Qt::AlignRight;
mychar = ab.data();
a = temp - 32;
b = a * 5/9;
Con_tem = QString::number(b,'f',1/*floor(b*10.0)/10.0*/);
i2 = Con_tem.count();
Con_ab = Con_tem.toLatin1().insert(i2,"°C");
align2 = Qt::AlignRight|Qt::AlignBottom;
Conv_char = Con_ab.data();
splash->show();
}
if(timePassed == 0)
{
//qDebug()<< timePassed;
splash->close();
splash->deleteLater();
HightempF = 0;
LowtempF = 0;
temp = 0;
stop();
memset(&Conv_char, 0, sizeof(Conv_char));
memset(&mychar, 0, sizeof(mychar));
deleteLater();
}
if(temp >= HightempF && HightempF != -999 && timePassed != 0)
{
if(timePassed == 5 || (TClock == "true" && timePassed == 2)){
splash->showMessage(tr(mychar),align,Qt::white);
splash->setFont(splashfont);
}
if(TClock == "true" && (timePassed == 2 || timePassed == 1))
InitImage.load(""+Snap_Smiley_Image_Path+QString("/high%1.png").arg(timePassed)+"");
else
InitImage.load(""+Snap_Smiley_Image_Path+QString("/high%1.png").arg(timePassed)+"");
painter.begin(&InitImage);
painter.setPen(Qt::white);
painter.setFont(QFont("Helvetica Neue Regular",22));
painter.drawText(InitImage.rect(),Qt::AlignTop|Qt: :AlignRight,Conv_char);
painter.end();
splash->setPixmap(InitImage);
}
else if(temp <= LowtempF && HightempF != -999 && timePassed != 0)
{
InitImage.load(""+Snap_Smiley_Image_Path+QString("/invalid%1.png").arg(timePassed)+"");
splash->setPixmap(InitImage);
}
else
{
if(timePassed == 5 || (TClock == "true" && timePassed == 2)){
splash->showMessage(tr(mychar),align,Qt::white);
splash->setFont(splashfont);
}
if(timePassed != 0)
{
if(TClock == "true" && (timePassed == 2 || timePassed == 1))
InitImage.load(""+Snap_Smiley_Image_Path+QString("/valid%1.png").arg(timePassed)+"");
else
InitImage.load(""+Snap_Smiley_Image_Path+QString("/valid%1.png").arg(timePassed)+"");
painter.begin(&InitImage);
painter.setPen(Qt::white);
painter.setFont(QFont("Helvetica Neue Regular",22));
painter.drawText(InitImage.rect(),Qt::AlignTop|Qt: :AlignRight,Conv_char);
painter.end();
splash->setPixmap(InitImage);
}
}
timePassed--;
}
};

#endif // TIMER_H


This is my code kindly check it and let me know if anything wrong in it.

Thanks

d_stranz
11th April 2020, 18:15
Sorry, no. Your code is unreadable. However, from just glancing at it, it appears you do not understand at all how a QTimer should be used but it is impossible to read unformatted code.

Post a new thread, and put your code formatted with proper indentation inside of CODE tags (as explained in my signature below) and then I will take a look after I can read it.

I won't respond to any more messages posted in this thread.