Edit QtDesigner "connect" - is it possible ?
-
I believe this has been asked before and do not recall how it was answered.
If it was "solved" or not , would it be OK to discuss the subject again?
QtDesigner Edit ->Edit Widgets "go to slot.." seems to build part of the "signal" . In my view "pushing a button " is an event , in Qt terminology it is a event called signal . ( Please correct me if I am wrong here.)
This part actually creates editable code , however , it seems to confuse the issue by mixing event / signal with actual function performed by the signal. It does not look anything related to "connect".QtDesigner Edit ->Edit Signals/Slots nicely "connect" two wiglets using GUI.
Works great if the action on destination widget is simple - such as "clear()".However, this very useful and intuitive GUI stops being user friendly when the action on destination widget gets more complex - such as illustrated bellow.
I do realize it is cluttered so I am including partial views and its description.
First line in Signal / slot editor function is to fill the "list" using
"doitemsLayout". Works as expected.My simple question is
where is the actual C++ code performing this doitemsLayout function ?My next objective is to click on item in the " list " and copy the item to "list_2" using QtDesigner .
Neither of the "connect" attempted do this.
Including list to list_2.This boils down to two basic questions:
is Qt Designer limited to actions likes clear() only ? By design?Is there any way to physically see the "connect" function ( both SIGNAL and SLOT as build by QtDesigner , then debug and edit it - especially the function ?
-
@AnneRanch said in Edit QtDesigner "connect" - is it possible ?:
My simple question is
where is the actual C++ code performing this doitemsLayout function ?In your
ListWidget.cpp
file or wherever your list was defined.is Qt Designer limited to actions likes clear() only ? By design?
Yes, QtDesigner is very limited. If you want to pass items around, you'll need to do that in your code.
Is there any way to physically see the "connect" function ( both SIGNAL and SLOT as build by QtDesigner , then debug and edit it - especially the function ?
QtDesigner only sets up the connection. The real code is still in your code file or in the Qt source when using "standard" slots like
QWidget::close()
.But you can check your connection in your
.ui
file. The designer is only the graphical representation of this XML ui file.
You can't debug in design mode. Only when debugging your source code, you will see what's going on.QtDesigner doent "build" anything. The "Edit Signals & Slots" function in QtD is a replacement for, e.g.
connect(ui->listWidget, &QListWidget::itemClicked, ui->plainTextEdit, &QPlainTextEdit::copy);
Nothing more, nothing less.
And, btw, this connection doesnt make sense at all :)If you really want to send your item or item properties to some other widget (display the item name in textEdit, or whatever), you have to do it by coding the signal slot connection in your
cpp
/h
.This is how your QtDesigner connections look like in your
ui
file. This is all what QtDesigner does.
-
@AnneRanch
I am not sure if this post is appropriate , but I am really looking for somebody who will participate in discussion.I have QtDesigner "connect" sort of working for ONE case .
What is puzzling is this
-
the "list" gets filled by other action - with three "items".
-
the "connect" - third line in attached screen shot - fills/ copy ONLY one item. The objective is to copy all items.
-
As expected - clicking / selecting an item in "list" adds it to "plaintextEdit_2"
-
Only "list" and "plaintextEdit" gives option to "appendPlainText" hence "copy" QString to QString .
Makes sense, but I like to see copy all "items" not a single string .
My guess is the text widgets contents ( string or item ) should match - but the widget titles are misleading.
Sorry for being persistent - back to experimenting.
-
-
@AnneRanch said in Edit QtDesigner "connect" - is it possible ?:
the "connect" - third line in attached screen shot - fills/ copy ONLY one item. The objective is to copy all items.
Because the given slots and signals have no logic involved. If you want to have some custom behavior, you need to "tell" your program what to do. The default slots can only provide default or very basic stuff.
The first user wants to copy 1 item, the second wants to copy all, the third wants to copy only 5... Qt cant provide default slots for every single possibilty...Only "list" and "plaintextEdit" gives option to "appendPlainText" hence "copy" QString to QString .
Makes sense, but I like to see copy all "items" not a single string .See answer above. This is no standard behavior. The QtD default connection is also only possible, if the signal and slot parameters match. You cant connect a signal that passes an item to a slot, that expects a
QString
, without adding further logic.You need to take your items, get their (
item->text()
) and then send theQString
returned to yourplainTextEdit
. Then YOU can decide, whether you want to add one, three, 500 or 7 million...Your slot could look like this
void MainWindow::sendItemsToTextEdit() { for ( int i = 0; i < ui->list.size(); i++) { ui->plainTextEdit->appendPlainText(ui->list.at(i)->text()); } }
-
@Pl45m4 Ok, what you saying is the QtDesigner is limited to some action which is really not implemented as normal "connect" QtCreator signal/ slot . Even the terminology is little different - no more just object but sender and receiver . Both limited to "current " object.
It is as "connect" but it is not editable as C code.
You said to check .ui file, but
QtDesigner .ui file opens only in GUI .How can I bypass that?
I have no issue with "connecting" widgets with comparable methods - string to string , item to item.
My current ask is to "connect" two dialogs and so far I have been using QtDesigner as a test bed. That is why I have been looking for a C code I could just modify - use different objects.
I should be able to "convert " the invisible "connect" created by QtDesigner to connect two objects using real "connect".
(QtDesigner is useful only on current object )Appreciate all your input, it is very helpful to be able to discuss the issue on the forum.
-
@AnneRanch said in Edit QtDesigner "connect" - is it possible ?:
You said to check .ui file, but
QtDesigner .ui file opens only in GUI .
How can I bypass that?It's just for you to see what happens, when you do something in your QtDesigner GUI.
Openui
file in design mode (like usual), then switch to "Edit-Mode" (2nd vertical tab from top at the very left menu bar orCtrl + 2
).
(Ctrl + 3
to go back to design mode)
You will see the XML version of what you did in QtDesigner. But this is not for editing! Edit yourui
in your GUI only to ensure that nothing goes wrong.My current ask is to "connect" two dialogs
What dialogs?
That is why I have been looking for a C code I could just modify - use different objects.
It's always the same procedure:
You have basically four things, you need to think of:
- What do I want to connect?
- sender object
- What action should trigger the result?
- signal
- Where should my connection go?
- receiver object
- What should happen, when this happens?
- slot / function in receiver
Then you already have all of the four parameters you need, to make the connection on your own.
Remember: You can access everything you add to your
ui
file by using theui->...
pointer.
So you can connect from or to yourlist
usingui->list
in your connect statement (or code in general).In your slot you can add your logic to create the behavior you want.
- What do I want to connect?
-
Hi,
You should take a look at the Calculator Form example.
From a learning point of view, I would recommend to start by reading the documentation associated with Qt Designer, dig in the examples and then start doing more involved stuff.
You should also take the time to read about Signals and Slots to have a better grasp of what each is and what you can and cannot do with them.