|
—
本帖被 XChinux 执行加亮操作(2010-10-22)
—
程序是想使用Dict.cn的WebAPI写一个翻译小程序,使用QNetworkManagerGet请求,程序中当在wordLine按回车时请求,连接槽this->reply = netMan->get(QNetworkRequest(url)); 在QNetworkManager的finished SIGNAL里处理请求返回的信息…… 问题是,有时候很正常,当更多的时候会发生如下错误: - The inferior stopped because it received a signal from the Operating System.
- Signal name :
- SIGSEGV
- Signal meaning :
- Segmentation fault
大家帮忙看下下面代码,这个是什么情况阿,刚学不久,先谢谢各位了 代码; dict.cpp文件 - #include "dict.h"
- Dict::Dict(QWidget *parent)
- : QWidget(parent)
- {
- this->wordLabel = new QLabel(tr("Word:"));
- this->wordLine = new QLineEdit;
- this->resultLabel = new QLabel(tr("Result:"));
- //this->resultView = new QWebView(this);
- this->resultTextEdit = new QTextEdit;
- mainLayout = new QGridLayout;
- mainLayout->addWidget(this->wordLabel,0,0);
- mainLayout->addWidget(this->wordLine,0,1);
- mainLayout->addWidget(this->resultLabel,1,0,Qt::AlignTop);
- mainLayout->addWidget(this->resultTextEdit,1,1);
- this->setLayout(mainLayout);
- this->setWindowTitle("Apple Dict");
- //按enter键或改变内容发生
- this->connect(this->wordLine,SIGNAL(textChanged(QString)),this,SLOT(changeWord()));
- this->connect(this->wordLine,SIGNAL(returnPressed()),this,SLOT(enterWordLine()));
- this->netMan = new QNetworkAccessManager(this);
- this->connect(this->netMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(httpFinished(QNetworkReply*)));
- }
- void Dict::enterWordLine(){
- //this->resultView->load(QUrl("http://dict.cn/mini.php?q=word"));
- //this->resultView->update();
- QUrl url("http://dict.cn/ws.php?q=word");
- this->reply = netMan->get(QNetworkRequest(url));
- this->connect(this->reply,SIGNAL(readyRead()),this,SLOT(replyReadyRead()));
- this->connect(this->reply,SIGNAL(finished()),this,SLOT(replyFinished()));
- this->connect(this->reply,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(replyError(QNetworkReply::NetworkError)));
- }
- void Dict::changeWord(){
- //this->resultView->load(QUrl("http://www.baidu.com"));
- //this->resultView->update();
- }
- void Dict::httpFinished(QNetworkReply *reply){
- QVariant statusCodeV = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
- if(statusCodeV.toInt() == 200){
- QByteArray bytes = reply->readAll();
- const QString string(bytes);
- this->resultTextEdit->setText(string);
- }
- else{
- }
- delete reply;
- }
- void Dict::replyReadyRead(){
- }
- void Dict::replyFinished(){
- }
- void Dict::replyError(QNetworkReply::NetworkError replyError){
- }
- 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;
- }
|