为什么第一个包含的类被识别但第二个包含的类却未被识别?

时间:2018-12-03 07:05:49

标签: qt class header-files

嗨,我有2个名为Search和Search2的类。当我将它们包含在qt的mainwindow.h中时,只有第一个包含的类可以识别,而第二个则不能。换句话说,如果我先包含search2.h然后包含search.h,它将无法识别Search。这些是我的头文件。有人可以帮忙吗?

mainwndow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtGui/QWidget>
#include "ui_mainwindow.h"
#include "search.h"
#include <QString>
#include <QStringList>
#include <QThread>
#include "search2.h"
 namespace Ui {
 class MainWindow;
 }

 class MainWindow : public QMainWindow
 {
   Q_OBJECT

 public:

QThread* thread1 ;
QThread* thread2 ;
Search*  mySearch;
Search2* mySearch2;

explicit MainWindow(QWidget *parent = 0);
~MainWindow();

float frequency;
QString freq ;
int flag;

signals:


private slots:

void  on_pushButton_2_clicked();
void  receive_from_object(QStringList);
void  receive_from_object1(QStringList);
void  receive_from_object2(QStringList);

void  on_pushButton_3_clicked();

private:

Ui::MainWindow *ui;

};

#endif // MAINWINDOW_H

search.h

#ifndef SEARCH_H
#define SEARCH_H

#include <QWidget>
#include <QObject>
#include <QMutex>
#include <QString>
#include <QStringList>
 #include <QDebug>
#include <qtimer.h>
#include <QtConcurrentRun>
#include <QMessageBox>
#include <QThread>
#include <QMessageBox>
#include <QWaitCondition>


namespace Ui {
class Search;
}

class Search : public QWidget
{
  Q_OBJECT

public:

explicit Search(QWidget *parent = 0);


void Input_param(float RFfreq);

~Search();

void requestWork();
void abort();

QStringList slist3;
QString freqLog;
double output_search[5] ;

private:
 Ui::Search *ui;

bool _abort;
bool _working;



 signals:
 void transmit_to_gui(QStringList);



 void finished();
 void workRequested();

 void frequencyFound(QStringList);
 void frequencyLog(QString) ;
 void finishedscan() ;

 public slots:
 void receiveDateBand(QString);
  };

 #endif // SEARCH_H

search2.h

#ifndef SEARCH_H
#define SEARCH_H

#include <QWidget>
#include <QObject>
#include <QMutex>
#include <QString>
#include <QStringList>
#include <QDebug>
#include <qtimer.h>
#include <QtConcurrentRun>
#include <QMessageBox>
#include <QThread>
#include <QMessageBox>
#include <QWaitCondition>

namespace Ui {
class Search2;
}

class Search2 : public QWidget
{
  Q_OBJECT

public:
explicit Search2(QWidget *parent = 0);


~Search2();


 void requestWork2();
 void abort2();

 QStringList slist3;
  QString freqLog;
 double output_search[5] ;

 private:
 Ui::Search2 *ui;

bool _abort;
bool _working;
//QMutex mutex;


signals:
void transmit_to_gui1(QStringList);
void transmit_to_gui2(QStringList);

void finished2();
void workRequested2();

void frequencyFound(QStringList);
void frequencyLog(QString) ;
void finishedscan2() ;


public slots:
void receiveDateBand2(QString) ;

};

#endif // SEARCH_H

先谢谢了。

1 个答案:

答案 0 :(得分:0)

现在完全确定是否是这个原因,但是在第二个类中,您添加了相同的标头定义:

#ifndef SEARCH_H instead of  #ifndef SEARCH2_H