Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-8552

QtCore DLL cannot be delay-loaded

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Out of scope
    • Icon: P2: Important P2: Important
    • None
    • 4.6.2
    • None
    • None
    • Windows XP, Visual Studio 2005

      Hi,

      We are facing a problem when trying to delay load Qt DLLs into an application. See description below.

      Best regards,
      Antoine Trux
      F-Secure

      Environment
      -----------
      Windows XP, Visual Studio 2005.

      Motivation for delay-loading Qt libraries
      -----------------------------------------
      We delay-load Qt libraries not for performance reasons, but in order to control the location from which they are loaded.

      Description of the problem
      --------------------------
      Our project file (.pro) contains the following directive:
      QMAKE_LFLAGS += /delayload:QtCored4.dll

      If our code uses QVector's default constructor, e.g.:
      QVector<int> foo;
      then we get this linking error:
      1>LINK : fatal error LNK1194: cannot delay-load 'QtCored4.dll' due to import of data symbol '"_declspec(dllimport) public: static struct QVectorData QVectorData::shared_null" (imp?shared_null@QVectorData@@2U1@A)'; link without /DELAYLOAD:QtCored4.dll

      If our code uses QMap's default constructor, e.g.:
      QMap<int, int> foo;
      then we get this linking error:
      1>LINK : fatal error LNK1194: cannot delay-load 'QtCored4.dll' due to import of data symbol '"_declspec(dllimport) public: static struct QMapData QMapData::shared_null" (imp?shared_null@QMapData@@2U1@A)'; link without /DELAYLOAD:QtCored4.dll

      If our code uses QList's (or QStringList's) default constructor, e.g.:
      QList<int > foo;
      then we get this linking error:
      1>LINK : fatal error LNK1194: cannot delay-load 'QtCored4.dll' due to import of data symbol '"_declspec(dllimport) public: static struct QListData::Data QListData::shared_null" (imp?shared_null@QListData@@2UData@1@A)'; link without /DELAYLOAD:QtCored4.dll

      Possible workarounds for QVector and QMap
      -----------------------------------------
      For QVector, instead of:
      QVector<int> foo;
      writing:
      QVector<int> foo(0); // 0 = initial size
      solves the linking problem.

      For QMap, instead of:
      QMap<int, int> foo;
      writing:
      std::map<int, int> emptyMap;
      QMap<int, int> map(emptyMap);
      solves the linking problem.

      No workarounds for QList
      ------------------------
      For QList (or QStringList), we could not find any workaround. The reason is that QList has only two constructors:
      1) QList() - the default constructor, which causes the linking problem
      2) QList(const QList<T>& other) - the copy constructor; this would not cause a linking problem, but then, how to you construct `other' in the first place?

      And trying to work around the problem by using QList's static functions:

      • QList<T>::fromSet(const QSet<T>& set)
      • QList<T>::fromStdList(const std::list<T>& list)
      • QList<T>::fromVector(const QVector<T>& vector)
        does not work either, because all these function internally use QList's default constructor.

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            sorvig Morten Sørvig
            atrux Antoine Trux
            Votes:
            3 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes