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. How to Promote to a Class at the Runtime

How to Promote to a Class at the Runtime

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 1.4k Views
  • 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.
  • R_IrudezuR Offline
    R_IrudezuR Offline
    R_Irudezu
    wrote on last edited by R_Irudezu
    #1

    I have a class for double clicking signal that derived from QLabel and it is ok to promote a QLabel item that drag&dropped in designer.

    But I am creating unspecific number of QLabels and QFrames etc. at the runtime. Number of items depends on a list count so it changes all the time. So the items are custom and i want to promote each item to that doubleClick class. Is it possible to do that. Promotion at runtime?

    Here is how i create QLabel items:

    QGridLayout *listItemsLayout = new QGridLayout;
    listItemsLayout ->setColumnStretch(0, 5);
    listItemsLayout ->setColumnStretch(1, 5);
    listItemsLayout ->setColumnStretch(2, 5);
    
    QList<QFrame *> frames; 
    QList<QLabel *> labels;
    QList<QLabel *> infoTextLabels;
    
    for(int i = 0; i < aListCountVariable; i++)
    {
        frames << new QFrame(ui->PageWidget1);
        labels << new QLabel(frames.at(i));
        infoTextLabels << new QLabel(frames.at(i));
    
        // other details, specifying labels and frames sizes, qss etc
        /* ... */
    }
    
    ui->containerWidget->setLayout(listItemsLayout );
    

    Keizoku wa chikaranari.

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      What items are 'custom'? Do you have a custom class derived from QLabel/QWidget? If so why not simply instantiate them?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      R_IrudezuR 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        What items are 'custom'? Do you have a custom class derived from QLabel/QWidget? If so why not simply instantiate them?

        R_IrudezuR Offline
        R_IrudezuR Offline
        R_Irudezu
        wrote on last edited by
        #3

        @Christian-Ehrlicher said in How to Promote to a Class at the Runtime:

        instantiate

        I think i used wrong word. What I tried to mean by saying custom is, the items are not created in designer. They had been created by code like i post above as code.

        I have a doubleClick class. And i can promote the designer added widgets to that class and i'm connecting them like this in the MainWindow constructor:

            connect(ui->testLabel1, SIGNAL(Mouse_DoubleClick()), this, SLOT(Mouse_DoubleClick()));
            connect(ui->testLabel2, SIGNAL(Mouse_DoubleClick()), this, SLOT(Mouse_DoubleClick()));
        

        It's working properly. Now i want to do the same to the labels or frames created by code like above. I don't how how to do, how to promote them to doubleClick class and how to connect them. Need help on this point.

        Keizoku wa chikaranari.

        jsulmJ 1 Reply Last reply
        0
        • R_IrudezuR R_Irudezu

          @Christian-Ehrlicher said in How to Promote to a Class at the Runtime:

          instantiate

          I think i used wrong word. What I tried to mean by saying custom is, the items are not created in designer. They had been created by code like i post above as code.

          I have a doubleClick class. And i can promote the designer added widgets to that class and i'm connecting them like this in the MainWindow constructor:

              connect(ui->testLabel1, SIGNAL(Mouse_DoubleClick()), this, SLOT(Mouse_DoubleClick()));
              connect(ui->testLabel2, SIGNAL(Mouse_DoubleClick()), this, SLOT(Mouse_DoubleClick()));
          

          It's working properly. Now i want to do the same to the labels or frames created by code like above. I don't how how to do, how to promote them to doubleClick class and how to connect them. Need help on this point.

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

          @R_Irudezu There is actually nothing to promote at runtime. You simply create your doubleClick instances instead of label.

          doubleClick tmp = new doubleClick(parent);
          connect(tmp, SIGNAL(Mouse_DoubleClick()), this, SLOT(Mouse_DoubleClick()));
          
          R_IrudezuR 1 Reply Last reply
          2
          • jsulmJ jsulm

            @R_Irudezu There is actually nothing to promote at runtime. You simply create your doubleClick instances instead of label.

            doubleClick tmp = new doubleClick(parent);
            connect(tmp, SIGNAL(Mouse_DoubleClick()), this, SLOT(Mouse_DoubleClick()));
            
            R_IrudezuR Offline
            R_IrudezuR Offline
            R_Irudezu
            wrote on last edited by R_Irudezu
            #5

            @jsulm Actually i didn't know there is no promote at runtime, but i also couldn't guess the solution is that easy. Thanks @jsulm

            Thank you @Christian-Ehrlicher

            Solution for my case:

            labels << new doubleClick(frames.at(i));
            labels.last()->connect(labels.last(), SIGNAL(Mouse_Pressed()), this, SLOT(Mouse_Pressed()));
            

            It works but i don't it is the efficient way or not.

            Keizoku wa chikaranari.

            jsulmJ 2 Replies Last reply
            0
            • R_IrudezuR R_Irudezu

              @jsulm Actually i didn't know there is no promote at runtime, but i also couldn't guess the solution is that easy. Thanks @jsulm

              Thank you @Christian-Ehrlicher

              Solution for my case:

              labels << new doubleClick(frames.at(i));
              labels.last()->connect(labels.last(), SIGNAL(Mouse_Pressed()), this, SLOT(Mouse_Pressed()));
              

              It works but i don't it is the efficient way or not.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by jsulm
              #6
              This post is deleted!
              1 Reply Last reply
              0
              • R_IrudezuR R_Irudezu

                @jsulm Actually i didn't know there is no promote at runtime, but i also couldn't guess the solution is that easy. Thanks @jsulm

                Thank you @Christian-Ehrlicher

                Solution for my case:

                labels << new doubleClick(frames.at(i));
                labels.last()->connect(labels.last(), SIGNAL(Mouse_Pressed()), this, SLOT(Mouse_Pressed()));
                

                It works but i don't it is the efficient way or not.

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

                @R_Irudezu said in How to Promote to a Class at the Runtime:

                It works but i don't it is the efficient way or not.

                Sure it is. But you can remove "labels.last()->" in front of connect() call.

                1 Reply Last reply
                0
                • Christian EhrlicherC Online
                  Christian EhrlicherC Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @R_Irudezu said in How to Promote to a Class at the Runtime:

                  connect(labels.last(), SIGNAL(Mouse_Pressed()), this, SLOT(Mouse_Pressed()));

                  And please use the new signal/slot syntax: https://wiki.qt.io/New_Signal_Slot_Syntax - it helps you to catch errors which would only be visible on runtime otherwise.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  R_IrudezuR 1 Reply Last reply
                  1
                  • Christian EhrlicherC Christian Ehrlicher

                    @R_Irudezu said in How to Promote to a Class at the Runtime:

                    connect(labels.last(), SIGNAL(Mouse_Pressed()), this, SLOT(Mouse_Pressed()));

                    And please use the new signal/slot syntax: https://wiki.qt.io/New_Signal_Slot_Syntax - it helps you to catch errors which would only be visible on runtime otherwise.

                    R_IrudezuR Offline
                    R_IrudezuR Offline
                    R_Irudezu
                    wrote on last edited by
                    #9

                    @Christian-Ehrlicher Good to know that, thanks for notifying me.

                    Keizoku wa chikaranari.

                    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