PDA

View Full Version : How does the "PREVIEW" option in Qt Designer work?



Charvi
18th April 2012, 08:50
Hi,

I want to implement a similar functionality like PREVIEW in Qt Designer on my embedded device. Means I will make a ui file in Qt Designer, then copy it to my embedded device. On this device I am planning to run my custom xml parser and the qt client app. The xml parser will parse the xml file and pass the data to the Qt client app which will then generate and display the form on the fly. This is what I understood of the preview facility of the Designer.

I wanted an expert advice on the feasibility of this idea taking into account that I plan to run the xml parser and the QT Client app on my not so sophisticated embedded device.

Also after the app displays the form I have to take user input put it into a packet and pass it to the server. Does this seem also feasible ?

- Charvi

wysota
18th April 2012, 09:14
Have a look at QUiLoader instead.

Charvi
19th April 2012, 07:53
Thank you I tried that. It seems to be just the thing I wanted.

But what if the ui file was not generated with Qt Designer? Means if I have a custom editor which works just like Qt Designer ( also having the signal slots editor like it ), but the predefined slots for widgets are not the same. They are as per my requirement. Will then also the QUiLoader class work in the same way?

wysota
19th April 2012, 10:10
But what if the ui file was not generated with Qt Designer?
Then it wouldn't be a ui file.


Means if I have a custom editor which works just like Qt Designer ( also having the signal slots editor like it ), but the predefined slots for widgets are not the same. They are as per my requirement. Will then also the QUiLoader class work in the same way?

I don't understand what you mean about those slots. Slots are slots, QUiLoader doesn't care about their names.

Charvi
19th April 2012, 11:23
I don't understand what you mean about those slots. Slots are slots, QUiLoader doesn't care about their names.

When I connect some signal from a widget to some slot of another using the Designer Signal/Slots Editor, then when the form is shown using QUiLoader the signal and slots connection works. Now in designer only predefined slots can be connected, there is no provision for defining a custom slot ( please correct me if I am wrong ).

In the same way if I create some custom editor where in I populate a list of widgets on one side ( these are derived from the original class with extra features, like some extra signals and slots ) and I have a drag and drop area on the other, where the form can be created. The file so generated will have .ui extension and will also be in the xml format. Is it possible to load this type of file dynamically with QUiLoader?

wysota
19th April 2012, 11:56
Now in designer only predefined slots can be connected, there is no provision for defining a custom slot ( please correct me if I am wrong ).
You are wrong. You can add signals and slots to the form object and to promoted widgets from the context menu.


The file so generated will have .ui extension and will also be in the xml format. Is it possible to load this type of file dynamically with QUiLoader?
If it's using the same semantics then obviously yes.

Charvi
19th April 2012, 12:07
You are wrong. You can add signals and slots to the form object and to promoted widgets from the context menu.

In Designer? I am sorry, from the post (http://www.qtcentre.org/threads/2195-Adding-slots-in-Designer) I perceived that we cannot "define" (write code for) custom signal and slots in Qt Designer. If its possible then can you show me how? Sorry for my ignorance, but if this makes it my problem gets simplified to a huge extent.

wysota
19th April 2012, 16:50
In Designer? I am sorry, from the post (http://www.qtcentre.org/threads/2195-Adding-slots-in-Designer) I perceived that we cannot "define" (write code for) custom signal and slots in Qt Designer.
Looking at my calendar I can see it's April 19th, 2012 today and not May 12th, 2006.

Charvi
20th April 2012, 07:56
Thanks for your efforts but I think you are misled.

Whether its 2006 or 2012, I believe writing code for a custom slots is not supported in Qt Designer. Well here are some latest posts which may not be objectionable:

1) http://stackoverflow.com/questions/7964869/qt-designer-how-to-add-custom-slot-and-code-to-a-button
2) http://stackoverflow.com/questions/4324418/where-does-the-code-for-a-new-slot-created-using-qt-designer-go

etcetera.

QUiLoader may be working in the following manner:

A) The Signal/ Slots connections made using the predefined signals and slots in the Designer are between the tags <signal></signal> and <slot></slot> within the <connection></connection> tag int he .ui file.
B) Next while loading the .ui file first the QUiLoader will parse the tags and look for the code of the signals and slots (with name in between the tags) in the Qt Library. It will fetch the code from from there and display the UI.

This way when the particular signal is emitted the code of the slot will be executed. So if I need to implement my custom signals and slots I have to write the corresponding class files (.cpp and .h) which will contain its code.

wysota
20th April 2012, 09:47
Whether its 2006 or 2012, I believe writing code for a custom slots is not supported in Qt Designer.
Nobody said anything about writing code for custom slots. UI class is not about writing any code, it's about connecting signals to slots (existing or not). The slots have to be implemented in appropriate classes. I don't see how it's related to your usecase. I think you are missing a point on how Designer works. If you promote one class (say QPushButton) into another (say MyCustomButton) that adds some signals and slots to its base class, you still have to provide that class in your final binary code and that's where you'll implement those missing slots. Designer doesn't allow you to create custom classes, it only allows to marshall instances of them. However you call your "custom ui tool", it will have to work exactly the same way.