• 10938阅读
  • 4回复

Segmentation fault这个错误,跪求解,先谢谢各位了阿 [复制链接]

上一主题 下一主题
离线baimingjiang
 
只看楼主 倒序阅读 楼主  发表于: 2010-07-19
— 本帖被 XChinux 执行加亮操作(2010-10-22) —
程序是想使用Dict.cn的WebAPI写一个翻译小程序,使用QNetworkManagerGet请求,程序中当在wordLine按回车时请求,连接槽this->reply = netMan->get(QNetworkRequest(url));

在QNetworkManager的finished SIGNAL里处理请求返回的信息……

问题是,有时候很正常,当更多的时候会发生如下错误:
  1. The inferior stopped because it received a signal from the Operating System.
  2. Signal name :
  3. SIGSEGV
  4. Signal meaning :
  5. Segmentation fault


大家帮忙看下下面代码,这个是什么情况阿,刚学不久,先谢谢各位了


代码;
dict.cpp文件
  1. #include "dict.h"
  2. Dict::Dict(QWidget *parent)
  3.     : QWidget(parent)
  4. {
  5.     this->wordLabel = new QLabel(tr("Word:"));
  6.     this->wordLine = new QLineEdit;
  7.     this->resultLabel = new QLabel(tr("Result:"));
  8.     //this->resultView = new QWebView(this);
  9.     this->resultTextEdit = new QTextEdit;
  10.     mainLayout = new QGridLayout;
  11.     mainLayout->addWidget(this->wordLabel,0,0);
  12.     mainLayout->addWidget(this->wordLine,0,1);
  13.     mainLayout->addWidget(this->resultLabel,1,0,Qt::AlignTop);
  14.     mainLayout->addWidget(this->resultTextEdit,1,1);
  15.     this->setLayout(mainLayout);
  16.     this->setWindowTitle("Apple Dict");
  17.     //按enter键或改变内容发生
  18.     this->connect(this->wordLine,SIGNAL(textChanged(QString)),this,SLOT(changeWord()));
  19.     this->connect(this->wordLine,SIGNAL(returnPressed()),this,SLOT(enterWordLine()));
  20.     this->netMan = new QNetworkAccessManager(this);
  21.     this->connect(this->netMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(httpFinished(QNetworkReply*)));
  22. }
  23. void Dict::enterWordLine(){
  24.     //this->resultView->load(QUrl("http://dict.cn/mini.php?q=word"));
  25.     //this->resultView->update();
  26.     QUrl url("http://dict.cn/ws.php?q=word");
  27.     this->reply = netMan->get(QNetworkRequest(url));
  28.     this->connect(this->reply,SIGNAL(readyRead()),this,SLOT(replyReadyRead()));
  29.     this->connect(this->reply,SIGNAL(finished()),this,SLOT(replyFinished()));
  30.     this->connect(this->reply,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(replyError(QNetworkReply::NetworkError)));
  31. }
  32. void Dict::changeWord(){
  33.     //this->resultView->load(QUrl("http://www.baidu.com"));
  34.     //this->resultView->update();
  35. }
  36. void Dict::httpFinished(QNetworkReply *reply){
  37.     QVariant statusCodeV = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
  38.     if(statusCodeV.toInt() == 200){
  39.         QByteArray bytes = reply->readAll();
  40.         const QString string(bytes);
  41.         this->resultTextEdit->setText(string);
  42.     }
  43.     else{
  44.     }
  45.     delete reply;
  46. }
  47. void Dict::replyReadyRead(){
  48. }
  49. void Dict::replyFinished(){
  50. }
  51. void Dict::replyError(QNetworkReply::NetworkError replyError){
  52. }
  53. Dict::~Dict()
  54. {
  55.     delete this->wordLabel;
  56.     delete this->wordLine;
  57.     delete this->resultLabel;
  58.     delete this->resultTextEdit;
  59.     delete this->mainLayout;
  60.     delete this->myHttp;
  61.     delete this->netMan;
  62.     delete this->reply;
  63. }


离线lexdene
只看该作者 1楼 发表于: 2010-07-21
代码好长……
我很懒的说……
离线wd007

只看该作者 2楼 发表于: 2010-07-21
代码长。

编译没有问题吗?

调试一下看看
欢迎访问我的博客,一起学习提高
http://blog.csdn.net/qter_wd007
离线kongkong
只看该作者 3楼 发表于: 2010-09-30
我在用QNetworkReply做下载的时候也碰到了segmentation fault, 不知道楼主解决了么。
离线steinlee

只看该作者 4楼 发表于: 2010-10-21
# Dict::~Dict()
# {
#     delete this->wordLabel;
#     delete this->wordLine;
#     delete this->resultLabel;
#     delete this->resultTextEdit;
#     delete this->mainLayout;
#     delete this->myHttp;
#     delete this->netMan;
#     delete this->reply;
# }

you can not delete these components because they are deleted by their parents
Looking for remote C/C++ and Qt 兼职
快速回复
限100 字节
 
上一个 下一个