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. Run the initialization everytime you start a dialog
Forum Updated to NodeBB v4.3 + New Features

Run the initialization everytime you start a dialog

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 3 Posters 1.9k Views 2 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.
  • S Offline
    S Offline
    Sucharek
    wrote on last edited by
    #1

    Hi, so the title might sound confusing, but here's what I'm trying to figure out.
    So every time you start a Qt application, it has an initialization.
    Like this (this one's a dialog):

    Dialog::Dialog(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::Dialog)
    {
        ui->setupUi(this);
    }
    

    But there's a problem with that.
    It only does it once (on application start), and that's a problem for me.
    So, is there a way, when I call a dialog to start, to execute something like this ALL the time?

    JonBJ 1 Reply Last reply
    0
    • S Sucharek

      Hi, so the title might sound confusing, but here's what I'm trying to figure out.
      So every time you start a Qt application, it has an initialization.
      Like this (this one's a dialog):

      Dialog::Dialog(QWidget *parent) :
          QDialog(parent),
          ui(new Ui::Dialog)
      {
          ui->setupUi(this);
      }
      

      But there's a problem with that.
      It only does it once (on application start), and that's a problem for me.
      So, is there a way, when I call a dialog to start, to execute something like this ALL the time?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Sucharek
      This initialization happens each time a fresh instance of a Dialog is created, rather than at application start time.

      If you want a freshly initialized instance create one with Dialog *dialog = new Dialog; or Dialog dialog; as appropriate, instead of keeping the old instance you had around.

      S 1 Reply Last reply
      0
      • JonBJ JonB

        @Sucharek
        This initialization happens each time a fresh instance of a Dialog is created, rather than at application start time.

        If you want a freshly initialized instance create one with Dialog *dialog = new Dialog; or Dialog dialog; as appropriate, instead of keeping the old instance you had around.

        S Offline
        S Offline
        Sucharek
        wrote on last edited by
        #3

        Hi @JonB, ok, but can I do this with an already existing dialog (like a class)?

        M 1 Reply Last reply
        0
        • S Sucharek

          Hi @JonB, ok, but can I do this with an already existing dialog (like a class)?

          M Offline
          M Offline
          mpergand
          wrote on last edited by
          #4

          @Sucharek said in Run the initialization everytime you start a dialog:

          Hi @JonB, ok, but can I do this with an already existing dialog (like a class)?

          Hi,

          It's vague, please explain what you want to do with a real use case.

          S 1 Reply Last reply
          0
          • M mpergand

            @Sucharek said in Run the initialization everytime you start a dialog:

            Hi @JonB, ok, but can I do this with an already existing dialog (like a class)?

            Hi,

            It's vague, please explain what you want to do with a real use case.

            S Offline
            S Offline
            Sucharek
            wrote on last edited by
            #5

            @mpergand, I want to execute a command, when the dialog gets executed.
            For more explanation, I'm executing a Qt designer form class. I make a dialog design, give it some functions, but everytime it gets executed, I need to update some variables, ui elements, etc., and I wanna do that everytime I execute it (everytime I do: dialog.exec())

            JonBJ M 2 Replies Last reply
            0
            • S Sucharek

              @mpergand, I want to execute a command, when the dialog gets executed.
              For more explanation, I'm executing a Qt designer form class. I make a dialog design, give it some functions, but everytime it gets executed, I need to update some variables, ui elements, etc., and I wanna do that everytime I execute it (everytime I do: dialog.exec())

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @Sucharek
              So put your extra initialization code after the ui->setupUi(this);, or in a method you write and call.

              S 1 Reply Last reply
              0
              • S Sucharek

                @mpergand, I want to execute a command, when the dialog gets executed.
                For more explanation, I'm executing a Qt designer form class. I make a dialog design, give it some functions, but everytime it gets executed, I need to update some variables, ui elements, etc., and I wanna do that everytime I execute it (everytime I do: dialog.exec())

                M Offline
                M Offline
                mpergand
                wrote on last edited by mpergand
                #7

                @Sucharek
                Hum, not sure to understand you correctly ...

                If you want to excute something after the dialog is showed, implement a method in that dialog and call it each time you need it.

                1 Reply Last reply
                0
                • JonBJ JonB

                  @Sucharek
                  So put your extra initialization code after the ui->setupUi(this);, or in a method you write and call.

                  S Offline
                  S Offline
                  Sucharek
                  wrote on last edited by
                  #8

                  @JonB yes, I put extra initialization code after the ui->setupUi(this);
                  @mpergand you said: implement a method and call it each time you need it. Yes, everytime I call it (or open it)

                  M JonBJ 2 Replies Last reply
                  0
                  • S Sucharek

                    @JonB yes, I put extra initialization code after the ui->setupUi(this);
                    @mpergand you said: implement a method and call it each time you need it. Yes, everytime I call it (or open it)

                    M Offline
                    M Offline
                    mpergand
                    wrote on last edited by
                    #9
                    Dialog::Dialog(QWidget *parent) :
                        QDialog(parent),
                        ui(new Ui::Dialog)
                    {
                        ui->setupUi(this);
                    
                    initialyze();
                    }
                    
                    Dialog::initialyze()
                    {
                    // initialyzing stuff here
                    }
                    
                    // somewhere in your prog
                    myDialog->initialyze();
                    
                    1 Reply Last reply
                    3
                    • S Sucharek

                      @JonB yes, I put extra initialization code after the ui->setupUi(this);
                      @mpergand you said: implement a method and call it each time you need it. Yes, everytime I call it (or open it)

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #10

                      @Sucharek
                      Depending on whether you create a new QDialog each time you show it or you keep one around and re-use it, either

                      Put what you want extra after ui->setupUi(this); in Dialog::Dialog().

                      Or do something like:

                      Dialog::doSomeStuffToTheUi()
                      {
                          ui->doSomething();
                      }
                      
                      // Outside world caller
                      dialog.doSomeStuffToTheUi();
                      dialog.exec();
                      

                      If that does not do what you want, you are either doing something wrong or you are not explaining what this fails to achieve.

                      1 Reply Last reply
                      1
                      • S Offline
                        S Offline
                        Sucharek
                        wrote on last edited by
                        #11

                        Hi, so @mpergand and @JonB, it works perfectly.
                        Thank you both for helping me :)

                        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