Qt World Summit: Register Today!

Connection problem

  • Hello i have made one test but i have problem on connection:
    this is the .h file
    @class Widget : public QWidget

    explicit Widget(QWidget *parent = 0);


    QNetworkAccessManager *manager;
    QList<QNetworkReply *> currentDownloads;

    private slots:

    void scarico_file_lista();
    void leggo_manager(QNetworkReply *reply);


    #endif // WIDGET_H@

    the .cpp is:

    @void Widget::scarico_file_lista(){
    QStringList lista_url ;
    lista_url << "http://www.test.net/44" << "http://www.test.net/45";
    for (int gytr = 0; gytr<lista_url.length(); gytr++){
    QUrl url;
    url = lista_url[gytr];
    manager = new QNetworkAccessManager;
    connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(leggo_manager(QNetworkReply *reply)));
    QNetworkRequest request(url);
    QNetworkReply *reply = manager->get(request);


    void Widget::leggo_manager(QNetworkReply *reply){
    int lllll = 0;
    I don't have the connection to the slot leggo_manager, wath is wrong?



  • Remove reply from SLOT in connect().

  • "QObject::connect":http://doc.qt.nokia.com/4.7/qobject.html#connect

    bq. Note that the signal and slots parameters must not contain any variable names, only the type.

  • And do not instantiate a new QNetworkAccessManager in every iteration of your loop! A single one is sufficient, create it just before you enter the loop. With your current solution you create a mass of memory leaks, as you loose every pointer but the last to the created QNetworkAccessManagers.

  • Even the last one is lost, as the manager pointer is out of scope after the loop and can not be referenced anymore after the loop has ended.

Log in to reply