简体   繁体   English

使用Eclipse中Qt Designer创建的Qt GUI

[英]Using a Qt GUI created by Qt Designer in Eclipse

i'm completely new to Qt but i managed to get some simple windows and frames to work. 我是Qt的新手,但我设法让一些简单的窗户和框架工作。 I'm running Eclipse on a 64 bit Kubuntu system. 我在64位Kubuntu系统上运行Eclipse。 After editing my code in Eclipse, im running qmake and make from command line. 在Eclipse中编辑我的代码后,我从命令行运行qmake和make。

Yesterday i gave a try to Qt Designer, which works fine for me, compared to "hard-code" the widgets and buttons in eclipse. 昨天我尝试了Qt Designer,这对我来说很好,相比之下,eclipse中的小部件和按钮的“硬编码”。 However, i won't switch to QT Creator because i'm very used to Eclipse. 但是,我不会切换到QT Creator,因为我已经习惯了Eclipse。

My goal is to create the GUI in Qt Designer and use the generated code in Eclipse. 我的目标是在Qt Designer中创建GUI并使用Eclipse中生成的代码。

Running qmake -project, qmake and make generates a header file for my Mainwindow, containing the class code. 运行qmake -project,qmake和make会为我的Mainwindow生成一个包含类代码的头文件。

But when i try to include this header file in my Eclipse code, make stops with an error because g++ can't find the header file (seems the header has not been created yet). 但是当我尝试在我的Eclipse代码中包含这个头文件时,因为g ++找不到头文件(似乎还没有创建头文件),因此停止并出现错误。

I have to admit, im still confused about the Qt building process. 我不得不承认,我仍然对Qt构建过程感到困惑。 So, how could i manage to design my GUI via Qt Designer and still use Eclipse as my coding IDE? 那么,我怎么能设法通过Qt Designer设计我的GUI并仍然使用Eclipse作为我的编码IDE?

Greetings, lugge 问候,lugge

Edit: My Eclipse Project is a "Empty Makefile Project". 编辑:我的Eclipse项目是一个“空Makefile项目”。 As far as i know, this means i have to take care of the whole build process. 据我所知,这意味着我必须处理整个构建过程。 Eclipse wont do anything for me. Eclipse不会为我做任何事情。

I have not tried running "make" from Eclipse because the Makefile has to be generated by qmake. 我没有尝试从Eclipse运行“make”,因为Makefile必须由qmake生成。 Thus, after eiting and saving my code in Eclipse i run qmake and make from command line. 因此,在Eclipse中编写并保存我的代码后,我从命令行运行qmake和make。

Qmake senses there is a .ui file and generates the header file for this class. Qmake检测到有.ui文件,并为此类生成头文件。 Problem is if i try to include this header in Eclipse, my source code file can't be compiled. 问题是如果我尝试在Eclipse中包含此标头,则无法编译我的源代码文件。

For me it seems thats when "make" invokes g++ with my source code file, the header of the GUI has not been created. 对我来说,似乎当“make”使用我的源代码文件调用g ++时,尚未创建GUI的标题。

So why am I doing it this way? 那我为什么这样做? Well, I don't want to be addicted to a IDE like Qt Creator or stuff. 好吧,我不想沉迷于像Qt Creator这样的IDE或其他东西。 Because that means, everony trying to compile my project needs meta-informations such as a config-file or project-specific settings for that specific IDE. 因为这意味着,尝试编译我的项目的everony需要元信息,例如特定IDE的配置文件或项目特定设置。

In my C-projects i use a handwritten Makefile, so you just need to have GCC installed (which you usually have) and type "make". 在我的C项目中,我使用手写的Makefile,所以你只需要安装GCC(你通常有)并输入“make”。

I'm trying to get as close as possible to this with Qt-projects. 我试图通过Qt项目尽可能接近这一点。

You need 4 things : 你需要4件事:

  • The .ui generated by Qt Designer Qt Designer生成的.ui

=> about.ui => about.ui

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>About</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
    <x>0</x>
    <y>0</y>
    <width>400</width>
    <height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>A Propos</string>
</property>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
  • The cpp / h associated with the .ui, for example this : 与.ui关联的cpp / h,例如:

An about Window (about.cpp) => 关于Window(about.cpp)=>

#include "about.h"
#include "ui_about.h"

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

About::~About()
{
    delete ui;
}

(about.h) => (about.h)=>

#ifndef ABOUT_H
#define ABOUT_H

#include <QDialog>

namespace Ui {
    class About;
}

class About : public QDialog
{
    Q_OBJECT
public:
    explicit About(QWidget *parent = 0);
    ~About();

private:
    Ui::About *ui;
};

#endif // ABOUT_H

In the .pro file 在.pro文件中

SOURCES += about.cpp
HEADERS += about.h
FORMS   += about.ui

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM