how too add an exciting ".ui" file to a "cpp widget application project"?
-
Hello,
I make an Qt Widgets Application in Qt Creator with window_no_000 class name and wanna add a exciting ".ui" file with window_no_001 class name that I made it before in another python project.
I add UI file to project and make ".h" and ".cpp" file for that but get some error on ".cpp" file and don't know where is problem.
I put all files here please help me.project tree menu:
project files:
TSC_app_cpp.pro:QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += c++11 # You can make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ main.cpp \ window_no_000.cpp \ window_no_001.cpp HEADERS += \ window_no_000.h \ window_no_001.h FORMS += \ window_no_000.ui \ window_no_001.ui # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target DISTFILES += \ icons/activity.svg \ icons/airplay.svg \ icons/alert-circle.svg \ icons/alert-octagon.svg \ icons/alert-triangle.svg \ icons/align-center.svg \ icons/align-justify.svg \ icons/align-left.svg \ icons/align-right.svg \ icons/anchor.svg \ icons/aperture.svg \ icons/archive.svg \ icons/arrow-down-circle.svg \ icons/arrow-down-left.svg \ icons/arrow-down-right.svg \ icons/arrow-down.svg \ icons/arrow-left-circle.svg \ icons/arrow-left.svg \ icons/arrow-right-circle.svg \ icons/arrow-right.svg \ icons/arrow-up-circle.svg \ icons/arrow-up-left.svg \ icons/arrow-up-right.svg \ icons/arrow-up.svg \ icons/at-sign.svg \ icons/award.svg \ icons/bar-chart-2.svg \ icons/bar-chart.svg \ icons/battery-charging.svg \ icons/battery.svg \ icons/bell-off.svg \ icons/bell.svg \ icons/bluetooth.svg \ icons/bold.svg \ icons/book-open.svg \ icons/book.svg \ icons/bookmark.svg \ icons/box.svg \ icons/briefcase.svg \ icons/calendar.svg \ icons/camera-off.svg \ icons/camera.svg \ icons/cast.svg \ icons/check-circle.svg \ icons/check-square.svg \ icons/check.svg \ icons/chevron-down.svg \ icons/chevron-left.svg \ icons/chevron-right.svg \ icons/chevron-up.svg \ icons/chevrons-down.svg \ icons/chevrons-left.svg \ icons/chevrons-right.svg \ icons/chevrons-up.svg \ icons/chrome.svg \ icons/circle.svg \ icons/clipboard.svg \ icons/clock.svg \ icons/cloud-drizzle.svg \ icons/cloud-lightning.svg \ icons/cloud-off.svg \ icons/cloud-rain.svg \ icons/cloud-snow.svg \ icons/cloud.svg \ icons/code.svg \ icons/codepen.svg \ icons/codesandbox.svg \ icons/coffee.svg \ icons/columns.svg \ icons/command.svg \ icons/compass.svg \ icons/copy.svg \ icons/corner-down-left.svg \ icons/corner-down-right.svg \ icons/corner-left-down.svg \ icons/corner-left-up.svg \ icons/corner-right-down.svg \ icons/corner-right-up.svg \ icons/corner-up-left.svg \ icons/corner-up-right.svg \ icons/cpu.svg \ icons/credit-card.svg \ icons/crop.svg \ icons/crosshair.svg \ icons/database.svg \ icons/delete.svg \ icons/disc.svg \ icons/divide-circle.svg \ icons/divide-square.svg \ icons/divide.svg \ icons/dollar-sign.svg \ icons/download-cloud.svg \ icons/download.svg \ icons/dribbble.svg \ icons/droplet.svg \ icons/edit-2.svg \ icons/edit-3.svg \ icons/edit.svg \ icons/external-link.svg \ icons/eye-off.svg \ icons/eye.svg \ icons/facebook.svg \ icons/fast-forward.svg \ icons/feather.svg \ icons/figma.svg \ icons/file-minus.svg \ icons/file-plus.svg \ icons/file-text.svg \ icons/file.svg \ icons/film.svg \ icons/filter.svg \ icons/flag.svg \ icons/folder-minus.svg \ icons/folder-plus.svg \ icons/folder.svg \ icons/framer.svg \ icons/frown.svg \ icons/gift.svg \ icons/git-branch.svg \ icons/git-commit.svg \ icons/git-merge.svg \ icons/git-pull-request.svg \ icons/github.svg \ icons/gitlab.svg \ icons/globe.svg \ icons/grid.svg \ icons/hard-drive.svg \ icons/hash.svg \ icons/headphones.svg \ icons/heart.svg \ icons/help-circle.svg \ icons/hexagon.svg \ icons/home.svg \ icons/image.svg \ icons/inbox.svg \ icons/info.svg \ icons/instagram.svg \ icons/italic.svg \ icons/key.svg \ icons/layers.svg \ icons/layout.svg \ icons/life-buoy.svg \ icons/link-2.svg \ icons/link.svg \ icons/linkedin.svg \ icons/list.svg \ icons/loader.svg \ icons/lock.svg \ icons/log-in.svg \ icons/log-out.svg \ icons/mail.svg \ icons/map-pin.svg \ icons/map.svg \ icons/maximize-2.svg \ icons/maximize.svg \ icons/meh.svg \ icons/menu.svg \ icons/message-circle.svg \ icons/message-square.svg \ icons/mic-off.svg \ icons/mic.svg \ icons/minimize-2.svg \ icons/minimize.svg \ icons/minus-circle.svg \ icons/minus-square.svg \ icons/minus.svg \ icons/monitor.svg \ icons/moon.svg \ icons/more-horizontal.svg \ icons/more-vertical.svg \ icons/mouse-pointer.svg \ icons/move.svg \ icons/music.svg \ icons/navigation-2.svg \ icons/navigation.svg \ icons/octagon.svg \ icons/package.svg \ icons/paperclip.svg \ icons/pause-circle.svg \ icons/pause.svg \ icons/pen-tool.svg \ icons/percent.svg \ icons/phone-call.svg \ icons/phone-forwarded.svg \ icons/phone-incoming.svg \ icons/phone-missed.svg \ icons/phone-off.svg \ icons/phone-outgoing.svg \ icons/phone.svg \ icons/pie-chart.svg \ icons/play-circle.svg \ icons/play.svg \ icons/plus-circle.svg \ icons/plus-square.svg \ icons/plus.svg \ icons/pocket.svg \ icons/power.svg \ icons/printer.svg \ icons/radio.svg \ icons/refresh-ccw.svg \ icons/refresh-cw.svg \ icons/repeat.svg \ icons/rewind.svg \ icons/rotate-ccw.svg \ icons/rotate-cw.svg \ icons/rss.svg \ icons/save.svg \ icons/scissors.svg \ icons/search.svg \ icons/send.svg \ icons/server.svg \ icons/settings.svg \ icons/share-2.svg \ icons/share.svg \ icons/shield-off.svg \ icons/shield.svg \ icons/shopping-bag.svg \ icons/shopping-cart.svg \ icons/shuffle.svg \ icons/sidebar.svg \ icons/skip-back.svg \ icons/skip-forward.svg \ icons/slack.svg \ icons/slash.svg \ icons/sliders.svg \ icons/smartphone.svg \ icons/smile.svg \ icons/speaker.svg \ icons/square.svg \ icons/star.svg \ icons/stop-circle.svg \ icons/sun.svg \ icons/sunrise.svg \ icons/sunset.svg \ icons/tablet.svg \ icons/tag.svg \ icons/target.svg \ icons/terminal.svg \ icons/thermometer.svg \ icons/thumbs-down.svg \ icons/thumbs-up.svg \ icons/toggle-left.svg \ icons/toggle-right.svg \ icons/tool.svg \ icons/trash-2.svg \ icons/trash.svg \ icons/trello.svg \ icons/trending-down.svg \ icons/trending-up.svg \ icons/triangle.svg \ icons/truck.svg \ icons/tv.svg \ icons/twitch.svg \ icons/twitter.svg \ icons/type.svg \ icons/umbrella.svg \ icons/underline.svg \ icons/unlock.svg \ icons/upload-cloud.svg \ icons/upload.svg \ icons/user-check.svg \ icons/user-minus.svg \ icons/user-plus.svg \ icons/user-x.svg \ icons/user.svg \ icons/users.svg \ icons/video-off.svg \ icons/video.svg \ icons/voicemail.svg \ icons/volume-1.svg \ icons/volume-2.svg \ icons/volume-x.svg \ icons/volume.svg \ icons/watch.svg \ icons/wifi-off.svg \ icons/wifi.svg \ icons/wind.svg \ icons/x-circle.svg \ icons/x-octagon.svg \ icons/x-square.svg \ icons/x.svg \ icons/youtube.svg \ icons/zap-off.svg \ icons/zap.svg \ icons/zoom-in.svg \ icons/zoom-out.svg RESOURCES += \ icons.qrc
window_no_000.h:
#ifndef WINDOW_NO_000_H #define WINDOW_NO_000_H #include <QMainWindow> QT_BEGIN_NAMESPACE namespace Ui { class window_no_000; } QT_END_NAMESPACE class window_no_000 : public QMainWindow { Q_OBJECT public: window_no_000(QWidget *parent = nullptr); ~window_no_000(); private: Ui::window_no_000 *ui; }; #endif // WINDOW_NO_000_H
window_no_001.h
#ifndef WINDOW_NO_001_H #define WINDOW_NO_001_H #include <QMainWindow> QT_BEGIN_NAMESPACE namespace Ui { class window_no_001; } QT_END_NAMESPACE class window_no_001 : public QMainWindow { Q_OBJECT public: window_no_001(QWidget *parent = nullptr); ~window_no_001(); private: Ui::window_no_001 *ui; }; #endif // WINDOW_NO_001_H
main.cpp:
#include "window_no_000.h" #include "window_no_001.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); window_no_001 w; w.show(); return a.exec(); }
window_no_000.cpp:
#include "window_no_000.h" #include "ui_window_no_000.h" window_no_000::window_no_000(QWidget *parent) : QMainWindow(parent) , ui(new Ui::window_no_000) { ui->setupUi(this); } window_no_000::~window_no_000() { delete ui; }
window_no_001.cpp:
#include "window_no_001.h" #include "ui_window_no_001.h" window_no_001::window_no_001(QWidget *parent) : QMainWindow(parent) , ui(new Ui::window_no_001) { ui->setupUi(this); } window_no_001::~window_no_001() { delete ui; }
window_no_000.ui:
window_no_001.ui:
errors when I want to build project:
What should I do?And another question:
what is #include "ui_window_no_000.h" and #include "ui_window_no_001.h" in cpp files?
there is no file such as ui_window_no_000.h or ui_window_no_001.h in project. -
@aria_aa said in how too add an exciting ".ui" file to a "cpp widget application project"?:
What should I do?
- clean up the build directory
- run
qmake
- rebuild project
Should work, code looks good.
And another question:
what is #include "ui_window_no_000.h" and #include "ui_window_no_001.h" in cpp files?
there is no file such as ui_window_no_000.h or ui_window_no_001.h in project.These files are automatically generated from your .ui files by
uic
. It's part of the build process in Qt, same as with it runningmoc
to generate meta-object functionality.