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 own UI to dialog

Adding own UI to dialog

Scheduled Pinned Locked Moved Solved General and Desktop
guibuttonclickdialog
12 Posts 2 Posters 13.1k Views
  • 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.
  • M mrjj
    24 Nov 2015, 17:56

    hi , you would create new dialog via
    New ->Qt->Form designer Class->Dialog Without buttons
    then it should have a blank UI file just like mainwindow and you can just add
    widgets to it.

    It seems you almost did that but constructor for you dialog should be like this
    Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
    {
    ui->setupUi(this);
    }

    to use the UI file
    ui(new Ui::Dialog) and ui->setupUi(this);
    so please try via the new menu

    A Offline
    A Offline
    aney
    wrote on 25 Nov 2015, 08:06 last edited by
    #3

    @mrjj

    Hi mrjj,

    thanks a lot for your answer!
    so I created a new Widget and without the ui(new UI::DialogDreh) and ui->setupUI(this); part everythings ok. When I push the button the window appears.

    But with this part I get an error references to the ui (error C2512: no appropriate default constructor available; and some more).

    What could that be?

    M 1 Reply Last reply 25 Nov 2015, 08:40
    0
    • A aney
      25 Nov 2015, 08:06

      @mrjj

      Hi mrjj,

      thanks a lot for your answer!
      so I created a new Widget and without the ui(new UI::DialogDreh) and ui->setupUI(this); part everythings ok. When I push the button the window appears.

      But with this part I get an error references to the ui (error C2512: no appropriate default constructor available; and some more).

      What could that be?

      M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 25 Nov 2015, 08:40 last edited by
      #4

      @aney
      Hi, if you create a new dialog via the New menu, it all should be ok. ?

      that error "no appropriate default constructor available;"
      normally means you create the object with

      A * = new A();

      but A dont have a constructor that takes zero parameters
      A constructor might be
      a(Widget *Parent)
      and wants to be constructed
      A * = new A(this);

      Bot if you copy & paste the error and the line it talks about , it will be easier to guess.

      A 1 Reply Last reply 25 Nov 2015, 08:59
      0
      • M mrjj
        25 Nov 2015, 08:40

        @aney
        Hi, if you create a new dialog via the New menu, it all should be ok. ?

        that error "no appropriate default constructor available;"
        normally means you create the object with

        A * = new A();

        but A dont have a constructor that takes zero parameters
        A constructor might be
        a(Widget *Parent)
        and wants to be constructed
        A * = new A(this);

        Bot if you copy & paste the error and the line it talks about , it will be easier to guess.

        A Offline
        A Offline
        aney
        wrote on 25 Nov 2015, 08:59 last edited by
        #5

        @mrjj

        the lines 8 - 13:

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

        the errors:

        1>dialogdreh.cpp(10): error C2512: 'Ui::DialogDreh': no appropriate default constructor available
        1>dialogdreh.cpp(11): error C2614: 'DialogDreh': illegal member initialization: 'ui' is not a base or member
        1>dialogdreh.cpp(12): error C2065: 'ui': undeclared identifier
        1>dialogdreh.cpp(12): error C2227: left of '->setupUi' must point to class/struct/union

        thanks again!

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 25 Nov 2015, 09:26 last edited by
          #6

          @aney said:
          Hi it seems you just added the lines to your existing dialog ?
          Like the " ui->setupUi(this);"
          you should create DialogDreh via the New ->Qt->Form designer Class->Dialog Without buttons
          so all the needed files are created.
          It seems no UI files has been generated.
          So I guessing you just added the lines ?
          Or?

          A 1 Reply Last reply 25 Nov 2015, 09:42
          0
          • M mrjj
            25 Nov 2015, 09:26

            @aney said:
            Hi it seems you just added the lines to your existing dialog ?
            Like the " ui->setupUi(this);"
            you should create DialogDreh via the New ->Qt->Form designer Class->Dialog Without buttons
            so all the needed files are created.
            It seems no UI files has been generated.
            So I guessing you just added the lines ?
            Or?

            A Offline
            A Offline
            aney
            wrote on 25 Nov 2015, 09:42 last edited by
            #7

            @mrjj
            My active window in Qt Designer was my main window (mondev), there I made a new Dialog without Buttons, a new window/file opened, I added a label and saved it in the mondev-folder.

            I'm coding in Visual Studio, so then I had to add the new dialogdreh.ui to my project manually. Also I had to create dialogdreh.cpp and dialogdreh.h manually.
            Is there any way it creates them automatically in my project?

            M 1 Reply Last reply 25 Nov 2015, 09:47
            0
            • A aney
              25 Nov 2015, 09:42

              @mrjj
              My active window in Qt Designer was my main window (mondev), there I made a new Dialog without Buttons, a new window/file opened, I added a label and saved it in the mondev-folder.

              I'm coding in Visual Studio, so then I had to add the new dialogdreh.ui to my project manually. Also I had to create dialogdreh.cpp and dialogdreh.h manually.
              Is there any way it creates them automatically in my project?

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 25 Nov 2015, 09:47 last edited by mrjj
              #8

              @aney
              Ah, if you use Visual Studio, then you must make
              sure that moc.exe is also run as it creates
              the needed ui_ file with c++ code.

              Do you use the qt plugin for Visual Studio ?

              --create dialogdreh.cpp and dialogdreh.h manually.
              that sounds a bit wrong as the wizard normally create the files for you.

              Are you using Express version of studio ?

              could u try this test project.
              its default mainwindow that open dialog when u press button.
              https://www.dropbox.com/s/svg1skt3ikvj0r1/defaultwithdialog.zip?dl=0

              If it dont work, I guess your are not properly setup to use UI files.

              A 1 Reply Last reply 25 Nov 2015, 10:08
              0
              • M mrjj
                25 Nov 2015, 09:47

                @aney
                Ah, if you use Visual Studio, then you must make
                sure that moc.exe is also run as it creates
                the needed ui_ file with c++ code.

                Do you use the qt plugin for Visual Studio ?

                --create dialogdreh.cpp and dialogdreh.h manually.
                that sounds a bit wrong as the wizard normally create the files for you.

                Are you using Express version of studio ?

                could u try this test project.
                its default mainwindow that open dialog when u press button.
                https://www.dropbox.com/s/svg1skt3ikvj0r1/defaultwithdialog.zip?dl=0

                If it dont work, I guess your are not properly setup to use UI files.

                A Offline
                A Offline
                aney
                wrote on 25 Nov 2015, 10:08 last edited by
                #9

                @mrjj

                Ok, I tried the same code in QtCreator and it worked :D
                So maybe I just use QtCreator for the beginning... seems to be easier!

                I used Visual Studio Professional with the Add-In. And yes, know I see under Debug -> moc_mondev.cpp etc. there's a red-minus-sign :/
                I think I have insufficient knowledge about Qt + VS, maybe just start with QtCreator+Designer :D

                But thanks so much for your help!

                M 1 Reply Last reply 25 Nov 2015, 11:23
                0
                • A aney
                  25 Nov 2015, 10:08

                  @mrjj

                  Ok, I tried the same code in QtCreator and it worked :D
                  So maybe I just use QtCreator for the beginning... seems to be easier!

                  I used Visual Studio Professional with the Add-In. And yes, know I see under Debug -> moc_mondev.cpp etc. there's a red-minus-sign :/
                  I think I have insufficient knowledge about Qt + VS, maybe just start with QtCreator+Designer :D

                  But thanks so much for your help!

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 25 Nov 2015, 11:23 last edited by
                  #10

                  @aney
                  Hi, seems something up with the setup. Normally the Add-In does all the work but
                  if using QCreator is fine then its a good solution. :)
                  Its a nice editor with many hidden gems.

                  A 1 Reply Last reply 25 Nov 2015, 11:40
                  0
                  • M mrjj
                    25 Nov 2015, 11:23

                    @aney
                    Hi, seems something up with the setup. Normally the Add-In does all the work but
                    if using QCreator is fine then its a good solution. :)
                    Its a nice editor with many hidden gems.

                    A Offline
                    A Offline
                    aney
                    wrote on 25 Nov 2015, 11:40 last edited by
                    #11

                    @mrjj
                    Yes, I think I will have a look later, maybe install the Add-In again. But I'm glad, that it wasn't the code - I already doubted me :D
                    Another question: where can I tag this topic as solved?

                    M 1 Reply Last reply 25 Nov 2015, 11:42
                    0
                    • A aney
                      25 Nov 2015, 11:40

                      @mrjj
                      Yes, I think I will have a look later, maybe install the Add-In again. But I'm glad, that it wasn't the code - I already doubted me :D
                      Another question: where can I tag this topic as solved?

                      M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 25 Nov 2015, 11:42 last edited by
                      #12

                      @aney
                      Yeah when meta compiler doesn't run, it all get a bit strange. :)

                      In first post , under it. to the right. is Topic Tools button. It can mark as solved.

                      1 Reply Last reply
                      0

                      12/12

                      25 Nov 2015, 11:42

                      • Login

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