QSplashScreen, how to add my QWidget!
-
raaghuu, I don't read that! Very important information! This change all!
Well, the QSplashScreen only works with QPixMap! I try to use a animated GIF to Pixmap and the pixmap shows a freeze image. I will look for a solution...
Thanks raaghuu, thanks Andre.
-
[quote author="Andre" date="1342012422"]there is also a mixup of parent and child in the code[/quote]
How? I don't seem to see it...
-
Animated GIF's can only be shown using [[doc:QMovie]], which you can use on a [[doc:QLabel]]. However, that excludes QSplashScreen, at least via the normal API.
It could be (I did not check) that QSplashScreen internally uses a QLabel to display the pixmap, and if so, you can probably get a handle to it using QObject::findChildren<T> and set a QMovie on it that way. However, this is undocumented, and may or may not work in a future version.
Use the source of QSplashScreen to find out...
-
Andre, my splashscreen already works with animated gif as you write here using Qlabel e etc...
So, I think that's gonna be easier to use a QDialog to create the same viewer/resource of QSplashScreen... What do you think?
-
[quote author="raaghuu" date="1342012825"]
[quote author="Andre" date="1342012422"]there is also a mixup of parent and child in the code[/quote]How? I don't seem to see it...[/quote]
It is exactly what you indicated: he was passing in a QWidget pointer in the assumption that it would become a child of the QSplashScreen, while in reality it would become the parent. Just what you said. Sorry for the confusion.
-
[quote author="Andre" date="1342013403"]
It is exactly what you indicated: he was passing in a QWidget pointer in the assumption that it would become a child of the QSplashScreen, while in reality it would become the parent. Just what you said. Sorry for the confusion.
[/quote]
Oh... Ok... I think I was trying to see something else... Hence the confusion... Thanks
-
Why QDialog don't show the Dialog when we execute "show();"?
QDialog only shows when I user the method "exec();". I try to build a similar Splash Screen using QDialog, but I need to use the show method working... The exec lock the aplication and nothing else is executed except when we close the dialog, as everyone knows...Any workaround or tip to solved that?
-
@
myDialog->show(); //...starts the dialog
myDialog->raise(); //...makes it the topmost widget(i.e, visible)
mydialog->activate(); //...gives focus to the widget
@ -
[quote author="dcbasso" date="1342030078"]Why QDialog don't show the Dialog when we execute "show();"?
QDialog only shows when I user the method "exec();". I try to build a similar Splash Screen using QDialog, but I need to use the show method working... The exec lock the aplication and nothing else is executed except when we close the dialog, as everyone knows...[/quote]
Most probably because you have no running event loop. Use <code>application.processEvents()</code> after showing the dialog. -
Or just make sure you have an eventloop spinning quickly, and that you return to it regulary.
/me thinks processEvents() is evil. A sometimes nessecairy evil, but an evil nonetheless.
-
I'm not quite sure if it is actually evil, but it usually indicates that you might be doing something evil (which requires you to use processEvents()).
But as you said, a necessary evil sometimes. A prime example beeing splash screens.
-
Man that's a complex task to do!
I made something like this:@
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
DialogIniciandoSistema splash(0);
splash.show();
splash.raise();
Database db(0);
QTimer::singleShot(500, &db, SLOT(init()));
QTimer::singleShot(3000, &splash, SLOT(close()));
QTimer::singleShot(3000, &w, SLOT(show()));
return a.exec();
}
@Well, when the "init()" is executed my animated icon on the Splash freezes!
I think that I will need user Threads!!!! Real theard...the init() code:
@
oid Database::init()
{
if (database.open()) {
QSqlQuery query(database);
if (createTables(query))
{
if (populateTables(query))
{
qDebug() << "Populado com sucesso.";
} else {
qDebug() << "Erro ao popular tabelas. " << query.lastError() ;
}
} else {
qDebug() << "Erro ao criar tabelas. " << query.lastError();
}
}
}
QSqlDatabase Database::getDatabase()
{
return this->database;
}
bool Database::createTables(QSqlQuery query)
{
bool retorno = true;
bool temp = false;
QStringList lista = readCreateTable().split("//");
for (int i=1; i<lista.length(); i++)
{
temp = query.exec( lista[i] );
retorno &= temp;
}
return retorno;
}
bool Database::populateTables(QSqlQuery query)
{
bool retorno = true;
bool temp = false;
QStringList lista = readPopulateTable().split("//");
for (int i=1; i<lista.length(); i++)
{
temp = query.exec( lista[i] );
if (! temp)
{
qDebug() << query.lastError() << " --> SQL: " << lista[i];
}
retorno &= temp;
}
return retorno;
}
QString Database::readCreateTable()
{
QFile file(":/database/CreateTable.sql");
if(!file.open(QIODevice::ReadOnly))
{
qDebug() << "error opening file: " << file.error();
return "";
}
QTextStream instream(&file);
QString createTable = instream.readAll();
file.close();
return createTable;
}
QString Database::readPopulateTable()
{
QFile file(":/database/PopulateTable.sql");
if(!file.open(QIODevice::ReadOnly))
{
qDebug() << "error opening file: " << file.error();
return "";
}
QTextStream instream(&file);
QString populateTable = instream.readAll();
file.close();
return populateTable;
}
@ -
I resolved using QThread, connect, QDialog!
Thanks all!