Good evening,
I have an application where I derive from QApplication ( OBox is my class derived from QApplication ) and I have some problems with a QSplashScreen.
Here I post some code:
The main.cpp
#include "OBox.h"
int main(int argc, char* argv[])
{
OBox application(argc, argv);
return application.exec();
}
#include "OBox.h"
int main(int argc, char* argv[])
{
OBox application(argc, argv);
return application.exec();
}
To copy to clipboard, switch view to plain text mode
and here the ctor of OBox where I would show the QSplashScreen:
#include "OBox.h"
#include <Windows.h>
#include <Dbt.h>
#include <QDesktopServices>
#include <QDateTime>
#include <QInputDialog>
#include <QProgressDialog>
#include <QMessageBox>
#include <QDebug>
#include <QSplashScreen>
#include <QPixmap>
#include "ReleaseVariables.h"
#include "Utilities.h"
OBox
::OBox(int
& argc,
char** argv
) : QApplication(argc, argv
){
// Initialize application info
setApplicationName(APPLICATION_TITLE);
setApplicationVersion(APPLICATION_VERSION);
splash
->setPixmap
(QPixmap(":/Resources/Splash.png"));
// <----- set the image I would show splash->show();// <---- after show it close immediately
qApp->processEvents();
// Initialize paths
m_userDataDir.setPath(dataDir.filePath("OBoxUserData"));
m_userDataDir.mkpath("."); // Make sure path exists (no problem if it's already there)
#ifndef DEVELOPMENT_MODE
if (m_applicationDir.exists("Plugins/Qt"))
{
libraryPaths.append(m_applicationDir.filePath("Plugins/Qt"));
}
setLibraryPaths(libraryPaths);
#endif
setQuitOnLastWindowClosed(true);
// Initialize objects
m_drivesUpdateTimer
= new QTimer(this);
m_drivesUpdateTimer->setSingleShot(true);
connect(m_drivesUpdateTimer, SIGNAL(timeout()), SLOT(updateDrives()));
m_mainWindow = new MainWindow(this);
m_mainWindow->showMaximized();
QTimer::singleShot(15000, splash,
SLOT(close
()));
// <------should close splash after 5s but doesn't have any effect
connect(this,
SIGNAL(sourceDirPathsChanged
(QStringList)),
splash->finish(m_mainWindow);
delete splash;
}
#include "OBox.h"
#include <Windows.h>
#include <Dbt.h>
#include <QDesktopServices>
#include <QDateTime>
#include <QInputDialog>
#include <QProgressDialog>
#include <QMessageBox>
#include <QDebug>
#include <QSplashScreen>
#include <QPixmap>
#include "ReleaseVariables.h"
#include "Utilities.h"
OBox::OBox(int& argc, char** argv) : QApplication(argc, argv)
{
// Initialize application info
setApplicationName(APPLICATION_TITLE);
setApplicationVersion(APPLICATION_VERSION);
QSplashScreen *splash = new QSplashScreen;// <---- create a QSplashScreen
splash->setPixmap(QPixmap(":/Resources/Splash.png"));// <----- set the image I would show
splash->show();// <---- after show it close immediately
qApp->processEvents();
// Initialize paths
m_applicationDir.setPath(QCoreApplication::applicationDirPath());
QString dataPath = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
QDir dataDir(dataPath);
m_userDataDir.setPath(dataDir.filePath("OBoxUserData"));
m_userDataDir.mkpath("."); // Make sure path exists (no problem if it's already there)
#ifndef DEVELOPMENT_MODE
QStringList libraryPaths;
if (m_applicationDir.exists("Plugins/Qt"))
{
libraryPaths.append(m_applicationDir.filePath("Plugins/Qt"));
}
setLibraryPaths(libraryPaths);
#endif
setQuitOnLastWindowClosed(true);
// Initialize objects
m_drivesUpdateTimer = new QTimer(this);
m_drivesUpdateTimer->setSingleShot(true);
connect(m_drivesUpdateTimer, SIGNAL(timeout()), SLOT(updateDrives()));
m_mainWindow = new MainWindow(this);
m_mainWindow->showMaximized();
QTimer::singleShot(15000, splash, SLOT(close()));// <------should close splash after 5s but doesn't have any effect
connect(this, SIGNAL(sourceDirPathsChanged(QStringList)),
m_mainWindow, SLOT(setSourceDirPaths(QStringList)));
splash->finish(m_mainWindow);
delete splash;
}
To copy to clipboard, switch view to plain text mode
The problem is that the splashscreen close immediately without wait the close() slot that should be called by the timer ( 5s after the splashscreen creation).
Where is the mystake(s) ?
I hope to get help.
Deleting the
delete splash;
delete splash;
To copy to clipboard, switch view to plain text mode
nothing changes.
Seems the timer has no effect. I know that the event loop shold start to have a timer working.
Regards
Franco
Bookmarks