Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/146.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Qt C++;使用在已创建对象中创建类的方法_C++_Qt_Class - Fatal编程技术网

C++ Qt C++;使用在已创建对象中创建类的方法

C++ Qt C++;使用在已创建对象中创建类的方法,c++,qt,class,C++,Qt,Class,我还是被卡住了 我有一个创建对象的GUI类。从这个新对象的方法中,我想使用创建类的方法 我有一个带有行编辑的Gui(PBV)和一个组合框。在这个组合框中,我可以选择不同的几何图形。Geo_1,Geo_2,…从几何体继承而来。根据组合框中的条目,我想创建不同的对象(Geo_1、Geo_2,…),然后根据Geo_n对象的需要设置创建类的线条编辑 我不想用信号槽做这件事 关于这一点我问了不同的问题,但我不能再进一步了 我觉得这是一种递归。。。有什么解决办法吗? 这是我的密码: PBV.h: #incl

我还是被卡住了

我有一个创建对象的GUI类。从这个新对象的方法中,我想使用创建类的方法

我有一个带有行编辑的Gui(PBV)和一个组合框。在这个组合框中,我可以选择不同的几何图形。Geo_1,Geo_2,…从几何体继承而来。根据组合框中的条目,我想创建不同的对象(Geo_1、Geo_2,…),然后根据Geo_n对象的需要设置创建类的线条编辑

我不想用信号槽做这件事

关于这一点我问了不同的问题,但我不能再进一步了

我觉得这是一种递归。。。有什么解决办法吗?

这是我的密码:

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.cpp:
#包括“Geometry.h”
#包括
#包括“Geo_1.h”
#包括“./Tabs/PBV.h”
Geo_1::Geo_1(QObject*\u父对象)
:几何体(_父项){}
void Geo_1::set_LNE_default()
{
//这里我想使用printContent
}

Geometry.h:
#ifndef几何
#定义几何图形
#包括
类几何体:公共QObject
{
Q_对象
公众:
几何图形(QObject*_parent=0);
~Geometry();
虚拟空集_LNE_default();
};
#endif//GEOMETRY\u H

Geometry.cpp:
#包括“Geometry.h”
#包括
几何体::几何体(QObject*_parent)
:QObject(_parent){}
几何体::~Geometry(){}
void Geometry::set_LNE_default(){}

当PBV分配一个Geo_1实例时,它已经在构造函数中传递一个指向自身的指针

GEO_1 = new Geo_1(this); // "this" is your PBV instance
为什么不保存指针以便以后使用

Geo_1::Geo_1(PBV*_parent) : Geometry((QObject*)_parent)
{
    this->pbv = _parent; // Save reference to parent
}
然后你可以做:

void Geo_1::set_LNE_default()
{
    // here I want to use printContent
    this->pbv->printContent(...); // this->pbv is your saved ptr to the PBV that created this instance
}
编辑

另外,您可能会遇到这样一个问题,即必须交叉包含两个标头(PBV和Geo_1),要解决此问题,请从PBV.h和Geo_1中删除include for Geo_1。就这样,

class Geo_1;

在声明PBV类之前。

当PBV分配Geo_1实例时,它已经在构造函数中向自身传递了一个指针:

GEO_1 = new Geo_1(this); // "this" is your PBV instance
为什么不保存指针以便以后使用

Geo_1::Geo_1(PBV*_parent) : Geometry((QObject*)_parent)
{
    this->pbv = _parent; // Save reference to parent
}
然后你可以做:

void Geo_1::set_LNE_default()
{
    // here I want to use printContent
    this->pbv->printContent(...); // this->pbv is your saved ptr to the PBV that created this instance
}
编辑

另外,您可能会遇到这样一个问题,即必须交叉包含两个标头(PBV和Geo_1),要解决此问题,请从PBV.h和Geo_1中删除include for Geo_1。就这样,

class Geo_1;

在声明PBV类之前。

这不起作用。当我在PBV.h中声明Geo:1 Geo_1时,他向我展示了正确的颜色(紫色和红色),表明他知道Geo_1。这没关系,因为我在PbV.h的顶部包含了“./Geometry/Geo_1.h”,但我仍然得到了错误:Geo_1没有命名类型,Geo_1的原型::Geo_1(PbV)与Geo_1类中的任何原型都不匹配。为什么?我觉得这和我的工作有关。这不起作用。当我在PBV.h中声明Geo:1 Geo_1时,他向我展示了正确的颜色(紫色和红色),表明他知道Geo_1。这没关系,因为我在PbV.h的顶部包含了“./Geometry/Geo_1.h”,但我仍然得到了错误:Geo_1没有命名类型,Geo_1的原型::Geo_1(PbV)与Geo_1类中的任何原型都不匹配。为什么?我觉得这和我的#includes有关