Adding own UI to dialog
-
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?
-
@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 withA * = 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.
-
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/unionthanks again!
-
@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? -
@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? -
@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=0If it dont work, I guess your are not properly setup to use UI files.
-
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 :DBut thanks so much for your help!