C++ Qt和C++;课堂上给我一个错误
我做错了什么C++ Qt和C++;课堂上给我一个错误,c++,qt,C++,Qt,我做错了什么 #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include "fileoperations.h" namespace Ui { class MainWindow; } class FileOperations; class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "fileoperations.h"
namespace Ui {
class MainWindow;
}
class FileOperations;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
FileOperations FileController;
private slots:
void on_OpenButton_clicked();
void on_SaveButton_clicked();
void on_EncodeButton_clicked();
void on_DecodeButton_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
奇怪的是,如果我更改“FileOperations FileController;”至“文件操作*文件控制器;”(很明显,这是错误的编译,因为您看不到的我的其他代码没有被改编成'->'而不是'.”)
然后,如果我将其更改回“FileOperations FileController;”它让我编译一次程序(它工作得很好),然后在我下次尝试编译它时它就会出错
我正在使用Qt5.0
fileoperations.h:
#ifndef FILEOPERATIONS_H
#define FILEOPERATIONS_H
#include "ui_mainwindow.h"
#include "mainwindow.h"
#include <QFileDialog>
#include <string>
#include <time.h>
#include <iostream>
#include <conio.h>
#include <windows.h>
#include <fstream>
using namespace std;
class FileOperations
{
public:
FileOperations();
void SetInputFile(QString x);
void SetOutputFile(QString x);
void EncryptAndSave(Ui::MainWindow *NUI);
void DecryptAndSave(Ui::MainWindow *NUI);
void createid(int id, int id2);
int GetCFuncion();
void SetCFuncion(int x);
long long Get_Size(string filename);
bool Get_Toobig(string path);
//DWORD WINAPI Thread_no_1();
private:
string InputFilename;
string OutputFilename;
int CFuncion;//CurrentFunction;
vector<int> conbyte1;
vector<int> conbyte2;
vector<int> opbyte1;
vector<int> opbyte2;
vector<int> passwordbytes;
};
#endif // FILEOPERATIONS_H
\ifndef文件操作\u H
#定义文件操作
#包括“ui_main window.h”
#包括“mainwindow.h”
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
类文件操作
{
公众:
文件操作();
void SetInputFile(QString x);
void SetOutputFile(QString x);
作废EncryptAndSave(Ui::MainWindow*NUI);
作废解密保存(Ui::MainWindow*NUI);
void createid(intid,intid2);
int GetCFuncion();
无效设置链接(int x);
long Get_大小(字符串文件名);
bool Get_Toobig(字符串路径);
//DWORD WINAPI线程编号1();
私人:
字符串输入文件名;
字符串输出文件名;
int CFuncion;//CurrentFunction;
向量conbyte1;
向量conbyte2;
向量opbyte1;
向量opbyte2;
向量密码字节;
};
#endif//FILEOPERATIONS\u H
由于您在类中持有一个FileOperations
对象,因此需要完整的类声明。这意味着您必须包含标题,不能像现在这样简单地向前声明类。如果您只持有一个指针,并且头中没有任何试图取消引用指针的代码,那么转发声明就足够了
编辑您有一个循环包含。您正在
fileoperations.h
中包含mainwindow.h
。您可以通过完全删除include来修复if。因为您在类中持有一个FileOperations
对象,所以需要完整的类声明。这意味着您必须包含标题,不能像现在这样简单地向前声明类。如果您只持有一个指针,并且头中没有任何试图取消引用指针的代码,那么转发声明就足够了
编辑您有一个循环包含。您正在
fileoperations.h
中包含mainwindow.h
。您可以通过完全删除包含来修复此问题。我假定,在.cpp文件中,您正在使用
#include "fileoperations.h"
然后,在fileoperations.h
中,您将包含main window.h
,它再次包含fileoperations.h
,这基本上是正确的,因为您使用的是fileoperations
对象作为参数。但是,由于有防护措施,类文件操作
这次不会被编译器看到,因此文件操作
在方法中用作参数时是未知的。您需要打破这种依赖关系:
在fileoperations.h
中,对Ui::MainWindow
使用转发声明并删除#include“MainWindow.h”
:
我假设,在您的.cpp文件中,您正在使用
#include "fileoperations.h"
然后,在fileoperations.h
中,您将包含main window.h
,它再次包含fileoperations.h
,这基本上是正确的,因为您使用的是fileoperations
对象作为参数。但是,由于有防护措施,类文件操作
这次不会被编译器看到,因此文件操作
在方法中用作参数时是未知的。您需要打破这种依赖关系:
在fileoperations.h
中,对Ui::MainWindow
使用转发声明并删除#include“MainWindow.h”
:
您有循环包含问题、mainwindow.h和fileoperations.h相互包含,请尝试从
fileoperations.h
#include "mainwindow.h"
您有循环包含问题、mainwindow.h和fileoperations.h相互包含,请尝试从
fileoperations.h
#include "mainwindow.h"
但是
fileoperations.h
也包括在内吗?@andrewfileoperations.h
是否有类声明?如果是,OP应说明。它可能坏了,我把fileoperations.h类放进去了,好了。你在FielActudio中包含了“MekWalth.h”。因此,编译器首先看到主窗口.H,不知道FileOperationsThankyou的任何内容,我真的需要学习事物的顺序:“我只学习C++ 3天,但是<代码>文件操作。h < /C>包括?”安德烈亚斯:fileoperations.h
是否有类声明?如果是,OP应说明。它可能坏了,我把fileoperations.h类放进去了,好了。您将“mainwindow.h”重新包含在fileoperations.h中-因此,编译器首先看到mainwindow.h,而对fileoperations一无所知谢谢,我真的需要了解事物的顺序是如何工作的:“我只学习了C++ 3天。<代码>文件操作。h < /C>看起来是什么样子?<代码>文件操作?h < /C>看起来是什么样的?