Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Connection problem
Qt 6.11 is out! See what's new in the release blog

Connection problem

Scheduled Pinned Locked Moved General and Desktop
5 Posts 5 Posters 3.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    luca72
    wrote on last edited by
    #1

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

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

    private:

    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);
    currentDownloads.append(reply);
    }

    }

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

    Thanks

    Luca

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DenisKormalev
      wrote on last edited by
      #2

      Remove reply from SLOT in connect().

      1 Reply Last reply
      0
      • S Offline
        S Offline
        secretNinja
        wrote on last edited by
        #3

        "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.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          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.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved