简体   繁体   中英

QWaitCondition: Destroyed while threads are still waiting

I'm having issues with my code and I need you to give me a hand please. I'm getting:

step 1
step 2
QSslSocket: cannot resolve TLSv1_1_client_method
QSslSocket: cannot resolve TLSv1_2_client_method
QSslSocket: cannot resolve TLSv1_1_server_method
QSslSocket: cannot resolve TLSv1_2_server_method
QSslSocket: cannot resolve SSL_select_next_proto
QSslSocket: cannot resolve SSL_CTX_set_next_proto_select_cb
QSslSocket: cannot resolve SSL_get0_next_proto_negotiated
step 3
step 4
Invalid parameter passed to C runtime function.
step 3
Invalid parameter passed to C runtime function.
ASSERT: "a && i >= 0 && i < (int)a->length" in file json\qjsonarray.cpp, line 527
QWaitCondition: Destroyed while threads are still waiting

I'm just ignoring QSslSocket errors cause I know it's due to https requests but I'm not using it. Here is my code:

TheMovieDB.cpp

TheMovieDB::TheMovieDB(QWidget *parent):QWidget(parent)
{
    qDebug()<<"step 1";
    t_api_key="?api_key=******************";
    t_api_url="http://api.themoviedb.org/3/";
    t_manager = new QNetworkAccessManager;
    t_resultID=0;
}    

void TheMovieDB::search(const QString &title)
{
    qDebug()<<"step 2";
    t_title=GeneralFunctions::prepareString(title); //on normalise la chaîne (retire les accents)
    t_api_query= t_api_url + "search/movie" + t_api_key + "&language=fr&query=" + title;
    t_manager->get(QNetworkRequest(QUrl(t_api_query)));
    QObject::connect(t_manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(readTitleSearch(QNetworkReply *)));
}

void TheMovieDB::readTitleSearch(QNetworkReply *reply)
{
    qDebug()<<"step 3";
    QString source = reply->readAll();
    QJsonDocument document = QJsonDocument::fromJson(source.toUtf8());
    QJsonObject jsonObj = document.object();
    QJsonArray obj = jsonObj["results"].toArray();
    QDate date;

    int distance=GeneralFunctions::distanceDL(t_title , obj[0].toObject()["title"].toString());
    t_resultID=obj[0].toObject()["id"].toInt();
    int distanceToBeCompared=0;

    for(int i = 1; i < obj.count(); i++){
        if(date.fromString(obj[i].toObject()["release_date"].toString(), "yyyy-MM-dd") < QDate::currentDate())
        {
            distanceToBeCompared=GeneralFunctions::distanceDL(t_title , obj[i].toObject()["title"].toString());
            if(distance > distanceToBeCompared)
            {
                distance=distanceToBeCompared;
                t_resultID=obj[i].toObject()["id"].toInt();
            }
        }
    }

    searchID(t_resultID);
}

void TheMovieDB::searchID(const int &id)
{
    qDebug()<<"step 4";
    t_api_query=t_api_url+"movie/"+QString::number(id)+t_api_key+"&language=fr";
    t_manager->get(QNetworkRequest(QUrl(t_api_query)));
    QObject::connect(t_manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(readIDSearch(QNetworkReply *)));
}


void TheMovieDB::readIDSearch(QNetworkReply *reply)
{
    qDebug()<<"step 5";

    /* some code */

    emit idSearchDone();
}

TheMovieDB.h

class TheMovieDB:public QWidget
{
    Q_OBJECT

public:
    TheMovieDB(QWidget *parent=0);
    void search(const QString &title);
    QMap<QString, QVariant> t_infosList;
    void searchID(const int &id);

private:
    QString t_title;
    QString t_api_url;
    QString t_api_key;
    QString t_api_query;
    int t_resultID;
    QString t_picturePath;
    QNetworkAccessManager* t_manager;

public slots:
    void readTitleSearch(QNetworkReply *reply);
    void readIDSearch(QNetworkReply *reply);    

signals:
    void idSearchDone();

};

Main.cpp

TheMovieDB tmdb;
tmdb.search("avatar");

I should have step 1,2,3,4,5. But I'm getting a second step 3 instead of step 5. Thank you for your help. The app is bugging when I'm launching it.

We have to disconnect the previous signal finished from readTitleSearch before connecting it again. To do it, add:

t_manager->disconnect(t_manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(readTitleSearch(QNetworkReply *)));

Before using it again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM