小编Gab*_*ini的帖子

Qt QString克隆分段错误

我正在使用Qt Creator构建我的第一个Qt应用程序,一切都很顺利,直到我从一条明显无害的线路开始得到一个奇怪的SIGSEGV.

这是错误:

程序接收信号SIGSEGV,分段故障.QBasicAtomicInt :: ref(this = 0x0)中的0x0804e2fe位于/usr/lib/qt/include/QtCore/qatomic_i386.h:120

通过在gdb上回溯异常,我发现当我返回属性时,一个简单的getter将NULL指针传递给克隆构造函数.

Backtrace输出:

(gdb) backtrace
#0 0x0804e2fe in QBasicAtomicInt::ref (this=0x0) at /usr/lib/qt/include/QtCore/qatomic_i386.h:120
#1 0x0804eb1b in QString (this=0xbfcc8e48, other=@0xbfcc8e80) at /usr/lib/qt/include/QtCore/qstring.h:712
#2 0x0805715e in Disciplina::getId (this=0xbfcc8e7c) at disciplina.cpp:13
[...]

检查传递给QString构造函数的指针:

(gdb)x 0xbfcc8e80
0xbfcc8e80:0x00000000

这是门徒.13:13

QString Disciplina::getId()
{
    return id;
}
Run Code Online (Sandbox Code Playgroud)

所以,所有指向QString的复制构造函数的点都接收到一个空指针,这对我来说毫无意义.id被声明为私有QString.

private:
    QString id;
Run Code Online (Sandbox Code Playgroud)

好吧,我不知道会发生什么,而且我的调试技巧只能到目前为止,所以如果有人可以提出一个想法我真的很高兴.

谢谢.

编辑

根据要求提供更多代码.

disciplina.h

#ifndef DISCIPLINA_H
#define DISCIPLINA_H
#include <QString>
#include <QMap>
#include "curso.h"
#include "turma.h"

class Curso;

class Turma;

class Disciplina
{
private:
    unsigned …
Run Code Online (Sandbox Code Playgroud)

c++ qstring qt pointers

1
推荐指数
1
解决办法
6358
查看次数

标签 统计

c++ ×1

pointers ×1

qstring ×1

qt ×1