×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Registered User
    Join Date
    Nov 2007
    Location
    Ibadan, Nigeria
    Posts
    214

    Ui Complier Functionality

    Hello All,
    I hand-coded the interface and design of a Qt application, which consists of several widgets and forms, without the use of the Qt Designer.. now i was wondering if it's possible to convert this Qt code into a .ui form file ? .i.e. anything designed on the Qt Designer normally can be converted to Qt code - my question is;is the reverse also possible ?

    Thanks for replies in advance.
    - David

  2. #2
    Registered User
    Join Date
    Nov 2007
    Location
    Ibadan, Nigeria
    Posts
    214

    Re: Ui Complier Functionality

    i understand your point. But in cases which might require integration of code into larger projects - designing the ui from the qt designer would be best at times.
    Actually tried the normal way -> designing with the qt designer ; hoping it would 'magically' convert my design into qt code(source and header files) - but it didn't work. Any ideas ?
    - David

  3. #3
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Ui Complier Functionality


  4. #4
    Regular Contributor
    Join Date
    Mar 2009
    Posts
    430

    Re: Ui Complier Functionality

    It is not possible to convert C++ Code to ui files. There was something in KDE that was able to write down a running QWidget down to a ui file but I doubt that it is worth trying out. Usually it does not take much time recreating a UI in Qt designer.

  5. #5
    Registered User
    Join Date
    Nov 2007
    Location
    Ibadan, Nigeria
    Posts
    214

    Re: Ui Complier Functionality

    Quote Originally Posted by divanov View Post
    Saw that while reading Qt Assistant, wasn't sure if'd work;will try it now.
    .......

    " Usually it does not take much time recreating a UI in Qt designer. "
    -> i know, but i'm having some trouble, at the moment, referencing some code in my source files that were implemented from the qt designer...
    - David

  6. #6
    Regular Contributor
    Join Date
    Mar 2009
    Posts
    430

    Re: Ui Complier Functionality

    Then show us that problems. It does not help if you work around a solvable problem.

  7. #7
    Registered User
    Join Date
    Nov 2007
    Location
    Ibadan, Nigeria
    Posts
    214

    Unhappy Re: Ui Complier Functionality

    Quote Originally Posted by divanov View Post
    That works (well i guess it already 'was supposed to').
    i tried to test it ;using the uic against a simple .ui file consisting of a Qmainwindow with a number of Qmenubars and items. When complied via uic, i get a header file with very long lines of code. ->possibly because it's converting from xml. -> i think i like hand-coding better.

    i got a question: i understand the differences between the single and multiple inheritance approaches:

    e.g. Single Inheritance:

    ui_Header File:
    class FormExtractor : public QWidget
    {
    Q_OBJECT

    public:
    FormExtractor(QWidget *parent = 0, Qt::WFlags flags = 0);
    ~FormExtractor();

    public slots:
    void setValues(const QString &firstName, const QString &lastName,
    const QString &gender, bool updates);

    void populateJavaScriptWindowObject();

    private:
    Ui::Form ui;
    };

    Part of ui_Source File:

    FormExtractor::FormExtractor(QWidget *parent, Qt::WFlags flags)
    : QWidget(parent, flags)
    {
    ui.setupUi(this);
    ui.webView->setUrl(QUrl("qrc:/form.html"));
    connect(ui.webView->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()),
    this, SLOT(populateJavaScriptWindowObject()));
    resize(300, 300);
    }

    An Advantage:
    The approach's simple use of inheritance to provide a QWidget-based interface, and its encapsulation of the user interface widget variables within the ui data member. Can use this method to define a number of user interfaces within the same widget, each of which is contained within its own namespace, and overlay (or compose) them. -in english-> easier to references UI's consisting of several widgets (of different types) via the use of namespaces.
    -------------------------------
    Multiple Inheritance:

    ui_Header File:
    class Previewer : public QWidget, public Ui::Form
    {
    Q_OBJECT

    public:
    Previewer(QWidget *parent = 0);

    void setBaseUrl(const QUrl &url);

    public slots:
    void on_previewButton_clicked();

    private:
    QUrl baseUrl;
    };

    Part of ui_Source File:
    Previewer::Previewer(QWidget *parent)
    : QWidget(parent)
    {
    setupUi(this);
    }
    //! [0]

    void Previewer::setBaseUrl(const QUrl &url)
    {
    baseUrl = url;
    }

    //! [1]
    void Previewer:n_previewButton_clicked()
    {
    // Update the contents in web viewer
    QString text = plainTextEdit->toPlainText();
    webView->setHtml(text, baseUrl);
    }

    An Advantage:
    Subclassing using multiple inheritance gives us more direct access to the contents of the form, is slightly cleaner than the single inheritance approach, but does not conveniently support composition of multiple user interfaces. -in english-> not a really smart choice if it involves UI's with several widgets. Though is much cleaner in appearance and allows more natural/better access to elements/objects on the form.

    ------------
    But when should each case be used ? What really determines when one should single over multiple or vice-versa ?
    Cuz many of the Qt example demos - > made use of a mixture of the two,some in more cases than the other, and quite a handful of the examples stick to designing their user interfaces by hand-code;not by use of the Qt designer. <- it's abit confusing keeping up with some of the examples. e.g. the Qt 'Demonstrations ->Main Window' example, that has all those many creepy docks.
    - David

  8. #8
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Ui Complier Functionality

    Quote Originally Posted by SoulBlade View Post
    That works (well i guess it already 'was supposed to').
    i tried to test it ;using the uic against a simple .ui file consisting of a Qmainwindow with a number of Qmenubars and items. When complied via uic, i get a header file with very long lines of code. ->possibly because it's converting from xml. -> i think i like hand-coding better.
    Yes, Qt Designer produces unreadable huge code and hides many things from you.

    Quote Originally Posted by SoulBlade View Post
    ui_Header File:
    class Previewer : public QWidget, public Ui::Form
    {
    I believe it should be
    Code:
    class Previewer : public QWidget, private Ui::Form
    To me multiple inheritance is preferable, but let's wait for an experts on this topic.

  9. #9
    Registered User
    Join Date
    Nov 2007
    Location
    Ibadan, Nigeria
    Posts
    214

    Re: Ui Complier Functionality

    i'm getting abit skeptical about using the uic to create my .ui header file.. maybe i should design the whole interface by code.
    I'm looking for a certain container in the qt designer -> in many adobe desktop applications, where you have the docked toolbars by the side, there's this tiny button icon that allows you to collapse the bar;what container has that functionality in the designer ? Cuz i played with all of them and their property settings,but didn't get any that closely matched what i was looking for.
    - David

  10. #10
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Ui Complier Functionality

    Quote Originally Posted by SoulBlade View Post
    i'm getting abit skeptical about using the uic to create my .ui header file.. maybe i should design the whole interface by code.
    uic produces header file out of .ui file. Contrary is not possible with uic.

  11. #11
    Regular Contributor
    Join Date
    Mar 2009
    Posts
    430

    Re: Ui Complier Functionality

    Why do you care at all about the generated code? The uic is invoked automatically during build process and the generated code gets overwritten every time then. See the uic-generated code as implementation detail like the code generated by moc. If you decide to code by hand because you dont like the generated code, then you have too much time. Use the provided tools. Be happy that there are tools.

    Regarding your question whether you should use multiple inheritance vs having UI:: as member:

    The advantage of having multiple inheritance is that you can threat for example a generated pushbutton exactly like you would access a pushbutton variable that you added to your header file as member.

    The advantage of having single inheritance and UI:: as member (in the case of a Ui:: pointer member) is that you can forward declare that class in the header and only have to include it in the cpp. Thus changing the ui file that triggers a rebuild of the generated header does not change the header and requires less recompiling.

    I do not understand your argument that you can use multiple generated forms within one class: I would use an own class for each generated form: First design the form in designer and then create a class that adds business logic to it. Now you have a component that hopefully has a sensible interface to the outside world that can be used much like one of the dialogs provided by Qt, for example QFileDialog or QMessageBox. Why would you want to use two generated forms within one class? This sounds to me as something that is not clean OOP and will not scale in the future.

Similar Threads

  1. QT Designer - UI widget access
    By davidmct in forum Qt
    Replies: 8
    Last Post: 2010-01-06, 13:31
  2. Ui Complier Functionality
    By SoulBlade in forum [Archived] Qt SDKs and Tools
    Replies: 1
    Last Post: 2010-01-05, 22:59
  3. Replies: 7
    Last Post: 2008-04-04, 09:41
  4. Event Notification UI Functionality
    By hardboy111 in forum Mobile Java General
    Replies: 6
    Last Post: 2007-09-24, 15:28
  5. Carbide.c++ UI Designer vs Game API
    By arachidyl in forum Symbian User Interface
    Replies: 4
    Last Post: 2006-10-25, 10:10

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×