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. Adding QTforms to existing project
Forum Updated to NodeBB v4.3 + New Features

Adding QTforms to existing project

Scheduled Pinned Locked Moved General and Desktop
11 Posts 2 Posters 10.4k Views 1 Watching
  • 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.
  • F Offline
    F Offline
    Franzk
    wrote on last edited by
    #2

    Quick walk-through:

    Create a .ui file

    Add the .ui file to your project

    In your class definition add: @namespace Ui {

    class MyClass;
    

    }

    class MyClass : public QWidget
    {
    ...
    private:
    Ui::MyClass *ui;
    };@

    In your implementation: @

    #include "ui_myclass.h"

    MyClass::MyClass(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MyClass)
    {
    ui->setupUi();
    }

    MyClass::~MyClass()
    {
    delete ui;
    }@

    "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

    http://www.catb.org/~esr/faqs/smart-questions.html

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Atom Byte
      wrote on last edited by
      #3

      Hi Franzk

      This is what i have done:
      Right click on the Addressbook.pro folder > Add New > QT > but from there i have 4 choices

      • Qt Designer Form Class
      • Qt Designer Form
      • Qt Resource file
      • Qt QML File

      I have tried with both form and form class and i'm not sure which i need. Either way i click next and have the new options dialog which displays with more choices. I am hesitating between a main window and a widget. I believe widget is the way to go.

      As i am sure you already know Form class will create a .h And a .cpp file alongside the ui file, this already contains the info you mentioned above. So i am guessing i need to use a form without class and add the info you provided to the existing .h and .cpp files. Am i along the right lines or am i barking up the wrong tree?
      If i do need a form without class, do i go main window or widget and finaly and probably the most important:

      Could you please explain what and where is the class definition that i need to add the above info to and when you say implementation, which file is that ( i thought it to be main.cpp)

      Thanks again

      1 Reply Last reply
      0
      • F Offline
        F Offline
        Franzk
        wrote on last edited by
        #4

        I was under the impression that you wanted to add a ui to an already existing class. If that's not the case, your approach is the proper one. If you create a new form & class using Qt Creator, a .ui, .h and .cpp will be created (say myclass.ui, myclass.h and myclass.cpp). The classes involved are then MyClass, which is a QWidget derived class, MyClass_Ui which is a helper class that doesn't do much except setting up the UI, and Ui::MyClass, which is the same thing as MyClass_Ui, only in a namespace possibly to avoid ugly naming or so. To use your new widget, your application should then instantiate a MyClass. The Ui::MyClass class is of no use to anything other than MyClass itself.

        "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Atom Byte
          wrote on last edited by
          #5

          Thanks for your replies Franzk, but i have tried and tried since your last post, and no matter what i do i can't get the info to display on the form. I have tried everyway i can possibly think off and its just not happening.

          yes i know i'm a noob and that Cpp is probably the hardest programming language for a noob to start with, and that i have a whole load of learning and reading (which i am doing) to do, but a little extra help from yourself or anyone else would be greatly appreciated.

          Maybe a do this and then do that approach would help a lot.

          I just want to get the existing addressbook tutorial to display on a form.

          Please anyone, Help me, its so frustrating when your at the bottom of the ladder.

          1 Reply Last reply
          0
          • F Offline
            F Offline
            Franzk
            wrote on last edited by
            #6

            So you're starting from the Addressbook example. Could you try to describe exactly what you want to add to it? And probably also what you already have done that worked out (in some way or another) for you? That will make it slightly easier for us to give you a recipe.

            "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Atom Byte
              wrote on last edited by
              #7

              Basicly i am following the tutorial (not the demo) and its all going as planned, except that something in the tutorial doesn't give the same result as the files included. Maybe i did something wrong, but i distinctly feel that the result and the tutorial examples are not the same.
              From there going directly to part 7 i see the whole example is there and already working (easier to learn with a full example).
              With all the files from part 7 open and browsing around i see there is no form for this working example. I basicly want to add a form and transfer the existing info, labels, buttons etc etc so they display within that new form.
              Maybe i have missed something or haven't made myself clear with my explanations.

              Thanks again, i understand it must be frustrating for hardened programmers such as yourself, when someone like myself has no idea where to start. But believe me i want to learn!

              1 Reply Last reply
              0
              • F Offline
                F Offline
                Franzk
                wrote on last edited by
                #8

                [quote author="Atom Byte" date="1298729745"]Thanks again, i understand it must be frustrating for hardened programmers such as yourself, when someone like myself has no idea where to start. But believe me i want to learn![/quote]Don't worry about that. Everyone was a beginner once :P. I'll see if I can get to it somewhere this weekend. Else I hope someone else picks up from here.

                "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  Atom Byte
                  wrote on last edited by
                  #9

                  Don't go out of your way man, weekends are precious. Just a little guidence would more than appreciated.

                  1 Reply Last reply
                  0
                  • F Offline
                    F Offline
                    Franzk
                    wrote on last edited by
                    #10

                    I didn't get to doing anything related to this. You got any progress?

                    "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      Atom Byte
                      wrote on last edited by
                      #11

                      For the moment no i haven't, its so frustrating. Then i had my machine go crazy, so i have formatted and am in the process of re-installing everything.

                      I think its down to installing wx widgets, dev c++, and a multitude of other programming tools to see what would be the easiest to learn with, but causing an eventual conflict somewhere.

                      I am at the point where i am about to re-install QT and nothing else (programming).

                      1 Reply Last reply
                      0

                      • Login

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