Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSplashScreen, how to add my QWidget!

QSplashScreen, how to add my QWidget!

Scheduled Pinned Locked Moved General and Desktop
20 Posts 4 Posters 9.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    andre
    wrote on last edited by
    #3

    Of course not. The SplashScreen object will be out of scope before the QSplashScreen has been shown...

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dcbasso
      wrote on last edited by
      #4

      I don't understand why, because the SplashScreen is only some texts and one animated gif.
      Where I can find some explanations about this Andre?

      Thanks

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #5

        It is basic C++, and it has nothing to do with what is on that widget. You'll find more on this issue in your favourite C++ book, in the chapter that deals with variable scopes.

        1 Reply Last reply
        0
        • R Offline
          R Offline
          raaghuu
          wrote on last edited by
          #6

          From The Docs:
          [quote]
          @QSplashScreen::QSplashScreen ( QWidget * parent, const QPixmap & pixmap = QPixmap(), Qt::WindowFlags f = 0 )@

          This is an overloaded function.

          This function allows you to specify a parent for your splashscreen. The typical use for this constructor is if you have a multiple screens and prefer to have the splash screen on a different screen than your primary one. In that case pass the proper desktop() as the parent.[/quote]

          As far as I understand, the widget you give is the parent and not the widget splash screen uses... your QSplashScreen makes a default (and empty) QPixMap and displays it as splash screen, but it is not visible as it is empty(NULL to be more specific)

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #7

            :-)
            True, there is also a mixup of parent and child in the code, but I thought I'd point out one issue at a time :-)

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dcbasso
              wrote on last edited by
              #8

              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.

              1 Reply Last reply
              0
              • R Offline
                R Offline
                raaghuu
                wrote on last edited by
                #9

                [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...

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #10

                  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...

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    dcbasso
                    wrote on last edited by
                    #11

                    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?

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      andre
                      wrote on last edited by
                      #12

                      [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.

                      1 Reply Last reply
                      0
                      • R Offline
                        R Offline
                        raaghuu
                        wrote on last edited by
                        #13

                        [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

                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          dcbasso
                          wrote on last edited by
                          #14

                          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?

                          1 Reply Last reply
                          0
                          • R Offline
                            R Offline
                            raaghuu
                            wrote on last edited by
                            #15

                            @
                            myDialog->show(); //...starts the dialog
                            myDialog->raise(); //...makes it the topmost widget(i.e, visible)
                            mydialog->activate(); //...gives focus to the widget
                            @

                            1 Reply Last reply
                            0
                            • L Offline
                              L Offline
                              lgeyer
                              wrote on last edited by
                              #16

                              [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.

                              1 Reply Last reply
                              0
                              • A Offline
                                A Offline
                                andre
                                wrote on last edited by
                                #17

                                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.

                                1 Reply Last reply
                                0
                                • L Offline
                                  L Offline
                                  lgeyer
                                  wrote on last edited by
                                  #18

                                  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.

                                  1 Reply Last reply
                                  0
                                  • D Offline
                                    D Offline
                                    dcbasso
                                    wrote on last edited by
                                    #19

                                    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;
                                    }
                                    @

                                    1 Reply Last reply
                                    0
                                    • D Offline
                                      D Offline
                                      dcbasso
                                      wrote on last edited by
                                      #20

                                      I resolved using QThread, connect, QDialog!
                                      Thanks all!

                                      1 Reply Last reply
                                      0

                                      • Login

                                      • Login or register to search.
                                      • First post
                                        Last post
                                      0
                                      • Categories
                                      • Recent
                                      • Tags
                                      • Popular
                                      • Users
                                      • Groups
                                      • Search
                                      • Get Qt Extensions
                                      • Unsolved