Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Singleton instance of QSplashScreen

    Wiki Discussion
    3
    20
    8484
    Loading More Posts
    • 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.
    • P
      prakash02 last edited by

      how to use QSplashScreen in an application of 100 files and each file has to change the message of QSplashScreen using showMessage.
      i.e., singleton instance of splash screen.

      pls any one show me light.

      1 Reply Last reply Reply Quote 0
      • D
        DenisKormalev last edited by

        You can make wrapper class for working with QSplashScreen and use it as singleton.

        1 Reply Last reply Reply Quote 0
        • P
          prakash02 last edited by

          since i'm a newbie ,could you please explain how to may use of wrapper class.

          1 Reply Last reply Reply Quote 0
          • D
            DenisKormalev last edited by

            Just create your own custom singleton-class which will have private QSplashScreen field and two public methods: one for setting this field (from place where you are creating splashscreen) and second for setting message.

            1 Reply Last reply Reply Quote 0
            • P
              prakash02 last edited by

              Thanks for ur reply..

              I have created the singleton class SplashScreen
              i'm using this
              SplashScreen::getInstance->setMessage();

              to set the message at different files.
              But still i have a doubt where to initialize QApplication.

              1 Reply Last reply Reply Quote 0
              • D
                DenisKormalev last edited by

                Mmm, QApplication is commonly initialized in main() method. Maybe you mean QSplashScreen? If yes, than I think it will be ok for you to init it in main() too.

                1 Reply Last reply Reply Quote 0
                • A
                  alexander last edited by

                  @class MySplash : public QSplashScreen
                  {
                  Q_OBJECT
                  public:
                  explicit MySplash(QObject parent = 0);
                  static MySplash
                  instance();

                  private:
                  MySplash* _inst;
                  }@
                  .cpp
                  @
                  MySplash
                  MySplash::_inst = 0;
                  MySplash* MySplash::instance()
                  {
                  if ( !_inst )
                  _inst = new MySplash();
                  return _inst;
                  }@

                  1 Reply Last reply Reply Quote 0
                  • P
                    prakash02 last edited by

                    @class SplashScreen : public QSplashScreen{

                    public:

                    static SplashScreen* getInstance();

                    void destroyInstance();
                    void SetSplashScreen();
                    void SetMessage(const std::wstring& message);
                    QString *splashMessage;
                    CString progressText;

                    private:
                    QSplashScreen *hostSplash_;
                    SplashScreen() {}

                    ~SplashScreen(){}

                    static SplashScreen* m_pInstance;

                    };@.h file

                    1 Reply Last reply Reply Quote 0
                    • P
                      prakash02 last edited by

                      @SplashScreen* SplashScreen::m_pInstance = NULL;

                      SplashScreen* SplashScreen::getInstance() {

                      if(NULL == m_pInstance ) {

                      m_pInstance = new SplashScreen();

                      }
                      return m_pInstance;
                      }

                      void SplashScreen::destroyInstance() {

                      delete m_pInstance;
                      m_pInstance = NULL;
                      }

                      void SplashScreen::SetMessage(const std::wstring& message ) {

                      progressText = message.c_str();
                      char pC = (char)(LPCTSTR)progressText ;
                      splashMessage->append(QString::fromAscii(pC));
                      hostSplash_->showMessage(*splashMessage);

                      }
                      void SplashScreen::SetSplashScreen() {
                      hostSplash_ = new QSplashScreen(QPixmap(":Resource Files/splash.jpg"));
                      }@

                      1 Reply Last reply Reply Quote 0
                      • A
                        alexander last edited by

                        prakash02, and?

                        1 Reply Last reply Reply Quote 0
                        • P
                          prakash02 last edited by

                          This is .cpp file.

                          I initialized the QApplication in main function, but my doubt does i can use the SplashScreen instance other than from main class.

                          Any help is appreciable.Thanks in advance.

                          1 Reply Last reply Reply Quote 0
                          • A
                            alexander last edited by

                            prakash02, @SplashScreen* SplashScreen::m_pInstance = NULL;@ it's C style, it's better to use C++ style:
                            @SplashScreen* SplashScreen::m_pInstance = 0;@

                            1 Reply Last reply Reply Quote 0
                            • A
                              alexander last edited by

                              And why do you use std::wstring instead QString?

                              1 Reply Last reply Reply Quote 0
                              • P
                                prakash02 last edited by

                                I defined resource file of strings,now i want to use those messages to be display on QSplashScreen when the program execution calls that function which can be on different namespace or on different class.

                                1 Reply Last reply Reply Quote 0
                                • D
                                  DenisKormalev last edited by

                                  Why do you use CString and std::wstring for setting/storing text? Why not QString? Also using CString and LPCTSTR type will break cross-platform compatibility.

                                  1 Reply Last reply Reply Quote 0
                                  • A
                                    alexander last edited by

                                    Denis Kormalev. :)

                                    1 Reply Last reply Reply Quote 0
                                    • D
                                      DenisKormalev last edited by

                                      2moderators of this section: please move this thread to more correspondent category (Desktop I think)

                                      1 Reply Last reply Reply Quote 0
                                      • A
                                        alexander last edited by

                                        prakash02, how do you defiine resource file of strings?

                                        1 Reply Last reply Reply Quote 0
                                        • P
                                          prakash02 last edited by

                                          Yes i can use QString, but previously those are used to display on the native windows dialog.Now I want to change those to QT to improve the look and feel.

                                          1 Reply Last reply Reply Quote 0
                                          • A
                                            alexander last edited by

                                            try to use QObject::tr("") for strings instead string table in resource file.

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post