C++;Qt—类T'时的奇怪行为;s属性的父项为T P>不确定QT或C++的一般问题,我只是这两个的新手!br> 我有一个简单的Qt应用程序,带有一个主窗口和Hello类,如下所示:

C++;Qt—类T'时的奇怪行为;s属性的父项为T P>不确定QT或C++的一般问题,我只是这两个的新手!br> 我有一个简单的Qt应用程序,带有一个主窗口和Hello类,如下所示:,c++,qt,C++,Qt,你好。h main window.h main.cpp 你能帮我解决这个问题吗 谢谢你 在“hello.h”和“maindwindow.h”中循环包含头文件。不需要在头文件中包含这些文件,因为您只需要使用指针。一个简单的前向声明,如class主窗口就足够了。在“hello.h”和“maindwindow.h”中循环包含头文件。不需要在头文件中包含这些文件,因为您只需要使用指针。一个简单的前向声明,如class主窗口就足够了 #ifndef HELLO_H #define HELLO_H #in

你好。h

main window.h

main.cpp

你能帮我解决这个问题吗

谢谢你

在“hello.h”和“maindwindow.h”中循环包含头文件。不需要在头文件中包含这些文件,因为您只需要使用指针。一个简单的前向声明,如
class主窗口就足够了。

在“hello.h”和“maindwindow.h”中循环包含头文件。不需要在头文件中包含这些文件,因为您只需要使用指针。一个简单的前向声明,如
class主窗口就足够了

#ifndef HELLO_H
#define HELLO_H

#include <QWidget>
#include "mainwindow.h"

class Hello : public QWidget
{
    Q_OBJECT
public:
    explicit Hello(MainWindow *parent = 0);

signals:

public slots:

};

#endif // HELLO_H
#include "hello.h"

Hello::Hello(MainWindow *parent) :
    QWidget(parent)
{
//nothing here yet
}
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QtGui/QMainWindow>
#include "hello.h"

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();

private:
    Hello* hi;
};

#endif // MAINWINDOW_H
#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    hi = new Hello(this);
}

MainWindow::~MainWindow()
{

}
#include <QtGui/QApplication>
#include "mainwindow.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}
explicit Hello(MainWindow *parent = 0);