Is this concept wrong / doable ?
-
wrote on 9 Nov 2021, 23:47 last edited by
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);
-
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);
wrote on 9 Nov 2021, 23:50 last edited by@AnneRanch you can use connect() and specify all the signal/slot methods, same as you'd click out in the designer.
-
wrote on 10 Nov 2021, 00:30 last edited by
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. -
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.wrote on 10 Nov 2021, 00:49 last edited by@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.
-
wrote on 10 Nov 2021, 13:00 last edited by
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. -
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.wrote on 10 Nov 2021, 13:05 last edited by@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.
- you create the object, i.e.
-
wrote on 10 Nov 2021, 15:07 last edited by
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.
-
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.
wrote on 10 Nov 2021, 16:18 last edited by@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.
4/8