Qt class disconnected from its .ui file?
Somehow my MainWindow
in my qt project has become unlinked from the .ui
I created in qt designer (I am using qt creator as my IDE). The implementation file does hav开发者_如何转开发e both:
#include "mainwindow.h"
#include "ui_mainwindow.h"
But if I add a widget (for example, a lineEdit
) into the UI in the designer, if I try to do anything with that widget in my implementation I get an error (and of course, the autocomplete does not detect that widget).
Can anyone assist? Please let me know if this is not descriptive enough. Thanks!
[EDIT]
This seems to be a problem with my moving from qt 4.6 to qt 4.7. In Qt4.6, the header files generated for the UI were put in the same directory as the project. In Qt4.7, it places them in the build directory. So I had updated header files, but my program was linking to the wrong one. Unfortunately, I can't seem to get it to link to the right header files now. Any ideas?Assuming a default qmake based project, when you create a new file you have the option of choosing whether or not it is added to the project. You choose this in the form of an "Add to Project" checkbox on the "Project Management" dialog.
To make sure the form is managed by QtCreator, edit your project's .pro
file so that it sees the .ui
file by adding an entry to FORMS
. For example, if you have one form, mainwindow.ui
, and a second newdialog.ui
that needs to be added, you could change it using any of the options below:
Option 1:
FORMS += mainwindow.ui \
newdialog.ui
Option 2:
FORMS += mainwindow.ui newdialog.ui
Option 3:
FORMS += mainwindow.ui
FORMS += newdialog.ui
The first option is used by QtCreator 1.3.1.
As long as the ui
files are registered in FORMS, the makefiles generated by qmake should be sufficient for the current version be it Qt-4.6 or Qt-4.7.
精彩评论