QT变量赋值,<没有这样的值>,SIGSEGV
QT variable assignment, <no such value>, SIGSEGV
我有 3 个分类,每个分类都有 3 个 int 类型的变量。还有 3 个成员函数,我尝试将这些变量分配给动态数组并返回数组。在第一种情况下,一切都很好,当我尝试从第二类和第三类分配变量时,问题就会出现。
#ifndef TANK_H
#define TANK_H
#include <QObject>
#include <QGraphicsScene>
#include <QGraphicsPixmapItem>
class Tank : public QObject, public QGraphicsPixmapItem
{
Q_OBJECT
public:
explicit Tank(QObject *parent = nullptr);
void setTanks(int x, int y, QGraphicsScene * scene);
void addTanks(int howMany = 0);
int * showStatisticsOfTank();
protected:
QGraphicsScene * scene;
int coordinateX, coordinateY;
int amountOfTanks;
int attack;
int defence;
int cost;
signals:
public slots:
};
#endif // TANK_H
在.cpp文件中:
int *Tank::showStatisticsOfTank()
{
int * arr = new int[3];
arr[0] = amountOfTanks;
arr[1] = attack;
arr[2] = defence;
return arr;
}
这行得通...但:
#ifndef WARPLANE_H
#define WARPLANE_H
#include <QObject>
#include <QGraphicsScene>
#include <QGraphicsPixmapItem>
class Warplane : public QObject, public QGraphicsPixmapItem
{
Q_OBJECT
public:
explicit Warplane(QObject *parent = nullptr);
void setWarplane(int x, int y, QGraphicsScene * scene);
void addWarplane(int howMany = 0);
int * showStatisticOfWarplane();
protected:
QGraphicsScene * scene;
int coordinateX, coordinateY;
int amountOfWarplanes;
int attack;
int defence;
int cost;
signals:
public slots:
};
#endif // WARPLANE_H
在.cpp文件中:
int *Warplane::showStatisticOfWarplane()
{
int * arr = new int[3];
arr[0] = amountOfWarplanes; //HERE ERROR SHOWS UP
arr[1] = attack;
arr[3] = defence;
return arr;
}
这不...SIGSEGV 错误出现,调试器在此行停止。当我试图查看战机数量,攻击和防御的价值时,它说:
<no such value>.
第三类几乎相同,当我注释掉第二类错误时,第三类的错误出现在同一个地方。我试图清理所有 ->重建,不起作用。
SIGSEGV 在尝试访问 amountOfWarplanes 时发生,后者是 Warplane 类的内部成员。这意味着它在尝试访问此内容时发生。
这些条件表明战机指针无效。
相关文章:
- 创建LinkedList退出,返回代码为-11(SIGSEGV)
- EASTL矢量<向量<int>>连续的
- SIGSEGV 使用shared_ptr引用时
- SIGSEGV, 分段错误. 而 printf() 数组索引的值
- SIGSEGV on Boost UDP 套接字关闭 - tcache_get at malloc.c.
- 分段故障 运行C++代码时出现 SIGSEGV
- 为什么我的递归代码给出 sigsegv 错误?
- 在使用堆栈为下一个最大数字编写代码时面临 SIGSEGV(分段错误)
- 在Hackerearth上获取运行时错误(SIGSEGV),无法找出代码中的问题
- 为什么在环路条件中使用'<='而不是'<'会产生分段错误 [SIGSEGV]?
- C++ - 程序接收信号SIGSEGV,分段错误.In msvcrt!memcpy () (C:\Windows\S
- 使用 dlopen 在 Mac 上加载 libjvm.dylib 时发出信号 SIGSEGV
- SIGSEGV通过写入局部变量
- 哪个部分导致"SIGSEGV"错误以及如何修复它?
- 进程过早退出,并发出 SIGSEGV 信号
- 我的代码上的运行时错误 sigsegv
- SIGSEGV 因为基/派生类的继承问题
- sqlite3 程序接收信号 SIGSEGV,分段错误在 sqlite3_get_table ()
- std::map to std::list leads to SIGSEGV
- 视觉 SIGSEGV 在C++碰撞预防