0
我仍然卡住。Qt C++使用在创建对象中创建类的方法
我有一个GUI类创建一个对象。从这个新的对象的方法我想要使用创建类的方法
我有一个Gui(PBV)与line_Edits和Combobox。在这个Combobox中,我可以选择不同的几何形状。从Geometry继承的Geo_1,Geo_2 ...。根据组合框中的条目,我想创建不同的对象(Geo_1,Geo_2,...),然后根据Geo_n-Object的需要设置创建类的lineEdits。
我don`want这样做与信号插槽
我问的是不同的问题,但我不能老是进一步得到。
我以某种方式感觉这是一种递归...是否有解决方案堡帽?
这里是我的代码:
PBV.h:
#include "../Geometry/Geo_1.h"
class PBV : public Tab
{
Q_OBJECT
public:
explicit PBV (QWidget *parent = 0);
~ PBV();
virtual void printContent(QStringList *const qsl);
private:
Geo_1 *GEO_1;
Geometry *GEO;
}
PBV.cpp:
…
Geo_1 *GEO_1;
GEO_1 = new Geo_1(this);
GEO_1->set_LNE_default();
…
。
Geo_1.h:
#ifndef GEO_1_H
#define GEO_1_H
#include "Geometry.h"
#include "../Tabs/PBV.h"
class Geo_1: public Geometry
{
Q_OBJECT
public:
Geo_1 (QObject *_parent = 0);
virtual void set_LNE_default();
};
#endif // GEO_1_H
。
Geo_1.cpp:
#include "Geometry.h"
#include <QDebug>
#include "Geo_1.h"
#include "../Tabs/PBV.h"
Geo_1::Geo_1(QObject*_parent)
: Geometry(_parent) {}
void Geo_1::set_LNE_default()
{
// here I want to use printContent
}
。
Geometry.h:
#ifndef GEOMETRY_H
#define GEOMETRY_H
#include <QObject>
class Geometry : public QObject
{
Q_OBJECT
public:
Geometry(QObject *_parent=0);
~Geometry();
virtual void set_LNE_default();
};
#endif // GEOMETRY_H
。
Geometry.cpp:
#include "Geometry.h"
#include <QDebug>
Geometry::Geometry(QObject *_parent)
: QObject(_parent) {}
Geometry::~Geometry(){}
void Geometry::set_LNE_default() { }
这不起作用。当我在PBV.h中声明一个Geo:1 * GEO_1时,他向我显示了正确的颜色(紫色和红色),表明他知道Geo_1。这是确定的,因为我在PbV上执行了#include“../Geometry/Geo_1.h”。h但是我仍然得到错误:Geo_1没有命名类型,Geo_1 :: Geo_1(PBV *)的原型与类Geo_1中的任何类型都不匹配。为什么???????我有印象这与我的#包含有关 – user3443063