Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qt 5.6 retrieving QObject sender
Forum Updated to NodeBB v4.3 + New Features

Qt 5.6 retrieving QObject sender

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 772 Views 2 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.
  • M Offline
    M Offline
    Mertanian
    wrote on last edited by Mertanian
    #1

    My project works fine with Qt 5.5.1 msvc 2013 problems occured when I switched
    to Qt 5.6.
    Here is simplified code (only not working part) for downloading file from ftp:

    void fun()
    {
    QNetworkAccessManager qnam; // in project it is class member
    QNetworkRequest request; // also class member
    request.setAttribute(QNetworkRequest::User, reqIndex); // lets say reqIndex = 0
    QNetworkReply* pReply = qnam.get(request); // also class member
    connect(pReply, SIGNAL(finished()), this, SLOT(onFinished()));
    connect(pReply, SIGNAL(downloadProgress(qint64,qint64)), this,
    SLOT(onDownloadProgress(qint64, qint64)));
    }
    
    void onFinished()
    {
    QNetworkReply* pCallerReply =
    dynamic_cast<QNetworkReply*>(QObject::sender());
    // pCallerReply is not nullptr
    int itemIndex = pCallerReply->request().attribute(QNetworkRequest::User, QVariant(-1)).toInt(&convertStatus;);
    // in Qt 5.6 itemIndex is always default QVariant(-1), convertStatus is true
    }
    
    // here is the same as onFinished()
    void onDownloadProgress(qint64, qint64)
    {
    QNetworkReply* pCallerReply =
    dynamic_cast<QNetworkReply*>(QObject::sender());
    // pCallerReply is not nullptr
    int itemIndex = pCallerReply->request().attribute(QNetworkRequest::User, QVariant(-1)).toInt(&convertStatus;);
    // in Qt 5.6 itemIndex is always default QVariant(-1), convertStatus is true
    }
    

    What could be a reason of this behavior? What can I do with it?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      The fact that you get -1 and convertStatus true just indicates that you are likely getting the default value.

      Can you create a minimal compilable example that shows that behavior ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      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