Qt网络访问管理器小部件应用程序崩溃

时间:2018-01-20 03:21:39

标签: c++ qt qnetworkaccessmanager qnetworkrequest

我正在创建一个gui应用程序,我将数据发送到我的Web服务并接收JSON响应。使用调试器我发现我设法发送数据并从我的服务器接收响应。但是,应用程序在明文中的值更改之前崩溃。一旦我将 AESEnkriptiraj 中的数组数量更改为两个,我就成功了,但即便如此,垃圾邮件按钮也会使应用程序崩溃。问题可能出在我的线程管理中,但我不知道它是什么。

decryptionwindow.h

#ifndef DECRYPTIONWINDOW_H
#define DECRYPTIONWINDOW_H

#include <QWidget>
#include "QFile.h"
#include "qfiledialog.h"
#include "qtextstream.h"
#include "kriptiraj.h"


namespace Ui {
class DecryptionWindow;
}

class DecryptionWindow : public QWidget
{
    Q_OBJECT


public:
    explicit DecryptionWindow(QWidget *parent = 0);
    ~DecryptionWindow();

signals:

public slots:
    void AESkriptiranoVrati(QString Poruka);

private:

private slots:
    void on_btnFilePath_clicked();

    void on_btnKriptirajAES_clicked();

    void on_btnDekriptirajAES_clicked();

private:
    Ui::DecryptionWindow *ui;
};

#endif // DECRYPTIONWINDOW_H

decryptionWindow.cpp

    #include "decryptionwindow.h"
#include "ui_decryptionwindow.h"
#include <QTextCodec>



Kriptiraj *kriptiraj= new Kriptiraj();


DecryptionWindow::DecryptionWindow(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::DecryptionWindow)
{
    ui->setupUi(this);
    connect(kriptiraj, SIGNAL(Poruka(QString)), this, SLOT(AESkriptiranoVrati(QString)));

}

void DecryptionWindow::on_btnKriptirajAES_clicked()
{

    kriptiraj->AESEnkriptiraj(ui->txtSadrzajDatotekeAES->toPlainText(), ui->txtKljucAES->toPlainText(), "AES", "Kriptiraj");

}

void DecryptionWindow::AESkriptiranoVrati(QString poruka){
    ui->txtSadrzajDatotekeAES->setPlainText(poruka);

}

kriptiraj.h

    #ifndef KRIPTIRAJ_H
#define KRIPTIRAJ_H

#include <qobject.h>
#include <qnetworkaccessmanager.h>
#include <qthread.h>
#include <QtScript/qscriptengine>
#include <QtScript/QScriptValueIterator>
#include <QNetworkReply>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QEventLoop>
#include <QDebug>

class Kriptiraj : public QObject
{
    Q_OBJECT
public:

    explicit Kriptiraj();
    ~Kriptiraj();



signals:
    Nastavi();
    Poruka(QString);


public slots:


    void AESEnkriptiraj(QString tekst, QString kljuc, QString metoda, QString zahtjev);

    QString IzvuciPodatak(QNetworkReply* reply);


private:

    QNetworkAccessManager *networkManager;
private slots:



};



#endif // KRIPTIRAJ_H

kriptiraj.cpp

    #include "kriptiraj.h"

Kriptiraj::Kriptiraj()
{
    networkManager= new QNetworkAccessManager();
    connect(networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(IzvuciPodatak(QNetworkReply*)));

}

void Kriptiraj::AESEnkriptiraj(QString tekst, QString kljuc, QString metoda, QString zahtjev){


    QNetworkReply* Reply;
    QString url ="http://jospudjaatfoi.000webhostapp.com/OS2/AESenkripcija.php?tekst="+tekst+"&kljuc="+kljuc+"&metoda="+metoda+"&zahtjev="+zahtjev;
    QUrl Url(url);
    QNetworkRequest Request;
    Request.setUrl(Url);
    Reply = networkManager->get(Request);

}

QString Kriptiraj::IzvuciPodatak(QNetworkReply* reply){


    QString data = (QString) reply->readAll();
    //reply->deleteLater();
    QJsonDocument JSON= QJsonDocument::fromJson(data.toUtf8());
    QJsonObject JSONObject = JSON.object();
    QJsonValue JSONValue = JSONObject.value("result");


    QString link =JSONValue.toString();
    emit Poruka(link);


}



Kriptiraj::~Kriptiraj()
{


}

基本上我有两个连接,一个在decryptionwindow初始化,另一个在kriptiraj初始化。代码继续运行 on_btnKriptirajAES_clicked(),运行 AESEnkriptiraj ,发送一个get请求,完成后使用连接运行 IzvuciPodatak 发出 Poruka 返回解密窗口连接,该连接运行 AESkriptiranoVrati 。之后就崩溃了。

对于错误的命名和其他做法感到抱歉,并抱歉在我的代码中使用母语并结合英语。

0 个答案:

没有答案