Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to open one time new widget
Qt 6.11 is out! See what's new in the release blog

How to open one time new widget

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
8 Posts 6 Posters 2.7k Views 3 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.
  • asttekinA Offline
    asttekinA Offline
    asttekin
    wrote on last edited by
    #1

    Hi all,

    I want to open full screen widget one time.A new widget is opening each click .

     fs *_fs = new fs(*this, 0);
     _fs->show(); 
    

    I tried this code but doesn't work.

    fs *_fs = new fs(*this, 0);
        if(!_fs->isVisible())
        {
            _fs->show();
        }
    
    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by A Former User
      #2

      Hi! What exactly "doesn't work"? Please provide a minimal example of what you're doing, say what you expect the code to do and what it actually does for you. Btw, to show a widget in full screen mode you can use void QWidget::showFullScreen().

      1 Reply Last reply
      0
      • asttekinA Offline
        asttekinA Offline
        asttekin
        wrote on last edited by
        #3
         fs *_fs = new fs(*this, 0);
         _fs->show(); 
        

        I used this code.But this code open a new widget every click.I want to open only one widget.How can I do that.

        kshegunovK 1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          Sure, because with new you create a new widget everytime

          1 Reply Last reply
          2
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi
            You should move the variable into the class

            class mainwin : xx {
            fs *_fs=NULL; // make sure its NULL
            };

            then say
            if (!_fs)
            _fs = new fs(*this, 0);

            Note its VERY IMPORTANT its set to NULL to begin with or u will crash.

            1 Reply Last reply
            3
            • R Offline
              R Offline
              raspe88
              wrote on last edited by
              #6

              There's a design pattern called "Singleton" that describes how to deal with the issue of creating "just one instance of a class for the whole program" - mrjj already told you the most important things about how it can be implemented in C++, but you can read more about it taking a look at e.g.:

              • Codeproject: Singleton Pattern & its implementation with C++
              • MSDN: Exploring the Singleton Design Pattern

              One remark regarding singleton and C++11: Since C++11 it is even possible to create a threadsafe singleton very easy:

              class Singleton {
              public:
                  static Singleton& getInstance() {
                      static Singleton instance;
                      return instance;
                  }
              };
              
              1 Reply Last reply
              1
              • asttekinA asttekin
                 fs *_fs = new fs(*this, 0);
                 _fs->show(); 
                

                I used this code.But this code open a new widget every click.I want to open only one widget.How can I do that.

                kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by
                #7

                @raspe88 said in How to open one time new widget:

                There's a design pattern called "Singleton"

                Indeed, there is such an antipattern. But @asttekin, I ask you, I beg you, I implore you, forget it exists and never follow links leading to it! It is like the road to hell - all paved with good intentions.

                Read and abide by the Qt Code of Conduct

                jsulmJ 1 Reply Last reply
                1
                • kshegunovK kshegunov

                  @raspe88 said in How to open one time new widget:

                  There's a design pattern called "Singleton"

                  Indeed, there is such an antipattern. But @asttekin, I ask you, I beg you, I implore you, forget it exists and never follow links leading to it! It is like the road to hell - all paved with good intentions.

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @kshegunov @raspe88 Not to mention that this antipattern is an exorbitant overhead in this case! It is really just a matter of checking whether the pointer is null or not.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  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