Important: Please read the Qt Code of Conduct -

Issue using QLatin1String as key in QHash since reinstall of Qt (and addition of new class)

  • UPDATE: I resubmitted this question "here": because I am nearly certain I have confirmed that the reinstall is NOT the issue.

    My OS hard drive crashed and I had to reinstall my OS on a new drive. Which means I had to reinstall everything else. I have been working on implementing another library into my project (irrlicht). About an hour ago I tried compiling everything again (build from scratch). This is the first several times I have tried building since I reinstalled the OS.

    For some reason I can no longer use QLatin1String as a key for the QHash template. This worked fine before. The compiler complains that QLatin1String doesn't have a default constructor (which seems to be true). If this is a problem, then why did it compile fine before? And why is their a hash function for qlatin1string in the documentation? Even if no one can answer these questions, am I supposed to be able to use QLatin1String as a key?

    I am using QLatin1String in combination with SEVERAL different classes. Here is an example of some code that worked fine before and hasn't compiled since my reinstall:
    @mObjectTables[n] = new QHash<QLatin1String, PersistentAppObject*>();@

  • Ok... I think I found part of the problem. Since no specific lines are given for the error, I did not know they all dealt with one new class in particular. But the output seems to suggest it has to do with this new class (BaseModInfo which does not have a default constructor). So could this be a bug with visual studio? It is reporting that the issue is with the key... not the value type. Or should I take it for its word? Is the QLatin1String really causing this problem?

    Here is the output when the error is produced:
    1>D:\Developing\Projects\IMT\API\3RD_PARTY\Qt\\5.3\msvc2012_opengl\include\QtCore/qhash.h(706): error C2512: 'QLatin1String::QLatin1String' : no appropriate default constructor available
    1> D:\Developing\Projects\IMT\API\3RD_PARTY\Qt\\5.3\msvc2012_opengl\include\QtCore/qhash.h(705) : while compiling class template member function 'const QLatin1String QHash<Key,T>::key(const T &) const'
    1> with
    1> [
    1> Key=QLatin1String,
    1> T=AppCore::BaseModInfo *
    1> ]
    1> d:\developing\projects\imt\rosweld\trunk\source\MyApp\Appcore\IAppInfoClass.h(115) : see reference to class template instantiation 'QHash<Key,T>' being compiled
    1> with
    1> [
    1> Key=QLatin1String,
    1> T=AppCore::BaseModInfo *
    1> ]@

  • Ok... so I am stuck. No default constructor with the BaseModInfo* class was not the issue because I created one and it made no difference.

    I am wondering if one of my classes is causing a problem because it is the only class that uses this particular QHash Type. And that use is in inheritance.

    @class APPCORE_EXPORT InfoCollection : public QHash<QLatin1String, BaseModInfo*>@

    Is it a bad idea to inherit from a QHash? The reason I need this is because I need a QHash of a QHash and I read somewhere that this was the only way to do it... Here is the class I need to contain a QHash of a QHash:

    @class APPCORE_EXPORT ModInfoCollection : public QHash<QLatin1String, InfoCollection*>@

  • Lifetime Qt Champion

    To avoid fragmenting the discussion let's close this one

    Continued "here":

Log in to reply