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. Is this concept wrong / doable ?
QtWS25 Last Chance

Is this concept wrong / doable ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 2 Posters 434 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.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on 9 Nov 2021, 23:47 last edited by
    #1

    The attached code partially , conceptually works - creates / adds new TAB to existing tab widget and then creates QTextEdit and adds results of "system" call. to it.
    I was hoping to be able to use mouse for further processing of the "system" " call results.
    However this is all dynamic and I cannot use "QTDesigner" "go to slot" option - as I usually do- on non existing QTextEdit. .

    I feel my concept execution is incorrect.

    I am open to suggestions...

        // set status
        ui->lineEdit_9->setText("on_comboBox_3_activated");
        // build a new tab
        // create new tab and add widget to it
        QTextEdit *text = new QTextEdit();
        QTextEdit *text_1 = new QTextEdit();
        // create new tab
        //QTabWidget *tab = new QTabWidget();
        text->setText("The quick brown fox jumps over lazy dog");
        text_1->setText("text ONE The quick brown fox jumps over lazy dog");
        // execute command
        system_command = arg1;
        // convert to char *
        QByteArray array = system_command.toLocal8Bit();
        char* buffer = array.data();
        //  Redirect(11,buffer,ui->textEdit_6);
        //  Redirect(11,buffer,ui->listWidget_3);
        Redirect(1,buffer,text);
        // create new tab and add widget to it
        ui->tabWidget->addTab(text, arg1);
    
    A 1 Reply Last reply 9 Nov 2021, 23:50
    0
    • A Anonymous_Banned275
      9 Nov 2021, 23:47

      The attached code partially , conceptually works - creates / adds new TAB to existing tab widget and then creates QTextEdit and adds results of "system" call. to it.
      I was hoping to be able to use mouse for further processing of the "system" " call results.
      However this is all dynamic and I cannot use "QTDesigner" "go to slot" option - as I usually do- on non existing QTextEdit. .

      I feel my concept execution is incorrect.

      I am open to suggestions...

          // set status
          ui->lineEdit_9->setText("on_comboBox_3_activated");
          // build a new tab
          // create new tab and add widget to it
          QTextEdit *text = new QTextEdit();
          QTextEdit *text_1 = new QTextEdit();
          // create new tab
          //QTabWidget *tab = new QTabWidget();
          text->setText("The quick brown fox jumps over lazy dog");
          text_1->setText("text ONE The quick brown fox jumps over lazy dog");
          // execute command
          system_command = arg1;
          // convert to char *
          QByteArray array = system_command.toLocal8Bit();
          char* buffer = array.data();
          //  Redirect(11,buffer,ui->textEdit_6);
          //  Redirect(11,buffer,ui->listWidget_3);
          Redirect(1,buffer,text);
          // create new tab and add widget to it
          ui->tabWidget->addTab(text, arg1);
      
      A Offline
      A Offline
      artwaw
      wrote on 9 Nov 2021, 23:50 last edited by
      #2

      @AnneRanch you can use connect() and specify all the signal/slot methods, same as you'd click out in the designer.

      For more information please re-read.

      Kind Regards,
      Artur

      1 Reply Last reply
      1
      • A Offline
        A Offline
        Anonymous_Banned275
        wrote on 10 Nov 2021, 00:30 last edited by
        #3

        OK, but where ?
        "all the way " where the initial tab is build ?
        Looks that way.
        For example my QTextEdit has to be "moved" up stream.
        Basically the "dynamic" creation is in wrong places.

        A 1 Reply Last reply 10 Nov 2021, 00:49
        0
        • A Anonymous_Banned275
          10 Nov 2021, 00:30

          OK, but where ?
          "all the way " where the initial tab is build ?
          Looks that way.
          For example my QTextEdit has to be "moved" up stream.
          Basically the "dynamic" creation is in wrong places.

          A Offline
          A Offline
          artwaw
          wrote on 10 Nov 2021, 00:49 last edited by
          #4

          @AnneRanch not true. if you place the connect() methods in the c'tor of the class of the ui there is no practical difference between placing the connections in the designer or somewhere else.

          For more information please re-read.

          Kind Regards,
          Artur

          1 Reply Last reply
          1
          • A Offline
            A Offline
            Anonymous_Banned275
            wrote on 10 Nov 2021, 13:00 last edited by
            #5

            I guess I do not understand how to implement signals/ slots for an object which does not exists AKA what I call "dynamic" object - created in code.
            In my case I like to create multiple of these "dynamic" objects . They would be identical but have individual signals / slots.
            I need to "rethink" this.

            A 1 Reply Last reply 10 Nov 2021, 13:05
            0
            • A Anonymous_Banned275
              10 Nov 2021, 13:00

              I guess I do not understand how to implement signals/ slots for an object which does not exists AKA what I call "dynamic" object - created in code.
              In my case I like to create multiple of these "dynamic" objects . They would be identical but have individual signals / slots.
              I need to "rethink" this.

              A Offline
              A Offline
              artwaw
              wrote on 10 Nov 2021, 13:05 last edited by
              #6

              @AnneRanch I fail to see what you fail to see.

              • you create the object, i.e. QTextEdit *edit = new QTextEdit(this); and insert it when appropriate in the form/layout. Just make sure it has a parent so it is deleted properly.
              • then you do connect() on that object.
              • back to line 1. This can be (and often is in my use cases) in the loop.

              I do that for zoom options or dynamic language switching with actions sometimes, works.

              For more information please re-read.

              Kind Regards,
              Artur

              1 Reply Last reply
              2
              • A Offline
                A Offline
                Anonymous_Banned275
                wrote on 10 Nov 2021, 15:07 last edited by
                #7

                Is this a good place to start - see link - ( again) to implement "connect" ?
                Not sure this is current document.
                It also refers to "studio" - I assume that is NOT referring to QTCreator.
                I cannot see "view" anywhere...

                https://doc.qt.io/qtcreator/quick-signals.html

                I am at a good point in my design and do not what to screw things up messing with "studio" if I do not have to.

                A 1 Reply Last reply 10 Nov 2021, 16:18
                0
                • A Anonymous_Banned275
                  10 Nov 2021, 15:07

                  Is this a good place to start - see link - ( again) to implement "connect" ?
                  Not sure this is current document.
                  It also refers to "studio" - I assume that is NOT referring to QTCreator.
                  I cannot see "view" anywhere...

                  https://doc.qt.io/qtcreator/quick-signals.html

                  I am at a good point in my design and do not what to screw things up messing with "studio" if I do not have to.

                  A Offline
                  A Offline
                  artwaw
                  wrote on 10 Nov 2021, 16:18 last edited by
                  #8

                  @AnneRanch "studio" here refers to the "design studio" program. It's (I think) outside the scope of our talk here. I was referring to the situation where you create widgets via c++. They will not be visible in the Creator but you can connect their signals and slots.
                  Consider this example (submenu with zoom levels):

                      zoomMenu = viewMenu->addMenu(tr("&Zoom level"));
                      zoomLevels = new QActionGroup(this);
                      for (auto x=10;x<210;x=x+10) {
                          QAction *act = new QAction(QString::number(x)+"%",this);
                          act->setCheckable(true);
                          zoomLevels->addAction(act);
                          connect(act,&QAction::triggered,this,[=](){setZoom(act->text());});
                      }
                      zoomMenu->addActions(zoomLevels->actions());
                  

                  Each action is connected (here via lambda).
                  With widget (same boilerplate application, QComboBox for zoom level):

                      zLevel = new QComboBox(this);
                      for (auto x=0;x<zoomLevels->actions().size();++x) {
                          zLevel->addItem(zoomLevels->actions().at(x)->text());
                      }
                      zLevel->addItem(tr("Fit to window"));
                      connect(zLevel,&QComboBox::currentTextChanged,this,&MainWindow::setZoom);
                      ui->toolBar->addWidget(zLevel);
                  

                  There is absolutely no need to use Creator for connecting signals and slot. I, personally, consider this a bad habit, as connections are not clearly visible in the code.

                  For more information please re-read.

                  Kind Regards,
                  Artur

                  1 Reply Last reply
                  3

                  4/8

                  10 Nov 2021, 00:49

                  • Login

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