Important: Please read the Qt Code of Conduct -

Errors when trying to include QUrlQuery

  • My colleague, developing in Qt4 on Ubuntu, has added a piece of code using the QUrl::addQueryItem. This gives me trouble when I try to compile the project in Qt5 on Windows, since the addQueryItem is supposedly deprecated.

    The solution that has been suggested to me is to use QUrlQuery::addQueryItem, and then QUrl::setQuery if QT_VERSION >= 5.0.0. However, whenever I try to include <QUrlQuery> in my code, I'm faced with a long list of errors from within the qurlquery.h file, as below:

    C:\Qt\Qt5.2.0\5.2.0\mingw48_32\include\QtCore\qurlquery.h:115: error: no 'void QUrl::setQueryItems(const QList<QPair<QString, QString> >&)' member function declared in class 'QUrl'
    C:\Qt\Qt5.2.0\5.2.0\mingw48_32\include\QtCore\qurlquery.h:117: error: no 'void QUrl::addQueryItem(const QString&, const QString&)' member function declared in class 'QUrl'
    C:\Qt\Qt5.2.0\5.2.0\mingw48_32\include\QtCore\qurlquery.h:119: error: no 'QList<QPair<QString, QString> > QUrl::queryItems() const' member function declared in class 'QUrl'

    The errors are all pointing to line 115-161 in qurlquery.h, so in the #if QT_DEPRECATED_SINCE(5,0)-block.

    Now, the unfortunate thing is that I can't seem to manage to reproduce this error in a minimal code, not even when copying both the .pro file and the file where I'm including <QUrlQuery>. Hence I don't expect a complete solution to the problem, but could anyone give me any tips as to how to start debugging this? I'm currently completely lost, and nothing that I do to my code (other than to comment out my inclusion of QUrlQuery) seems to make any difference.

  • I think the problem is that you use QUrl::addQueryItems in your code. Try to search it and replace it with :

    @QUrlQuery params;
    params.addQueryItem("", "");@

    These old URL functions are deprecated since Qt 5.0

  • [quote author="euchkatzl" date="1422885897"]I think the problem is that you use QUrl::addQueryItems in your code. Try to search it and replace it with :

    @QUrlQuery params;
    params.addQueryItem("", "");@

    These old URL functions are deprecated since Qt 5.0[/quote]

    No, I've removed this in my code already. I tried to describe this in the second paragraph of my post, that I'm replacing the QUrl::addQueryItem with QUrlQuery::addQueryItem. Even if I remove every instance of both QUrl::addQueryItem and QUrlQuery::addQueryItem, then I can still trigger the error on or off by adding or removing #include <QUrlQuery>.

    Edit: Just to clarify: The "no member function declared in class 'QUrl'" errors actually points to within the qurlquery.h file. It puzzles me how qurlquery.h is supposed to use QUrl::addQueryItem (along with a whole bunch of other deprecated QUrl member functions) if I can't.

  • Could you post a code snippet of your url creation ?

  • Absolutely. But as you can see, everything related to actually using addQueryItem (whether for QUrl or QUrlQuery) is commented out. I doubt that it's related to that part of my code, since the error is trigged whenever I try to include <QUrlQuery>, even if I do so in a completely clean QDialog class.

    In my .h file:

    #include <QDialog>
    //#include <QUrlQuery>
    #include <QUrl>@


    @QUrl* _url;
    //QUrlQuery* _query;@

    In my .cpp file:
    @ _url = new QUrl("");
    #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
    // _url->addQueryItem("version", VERSION);
    // _query = new QUrlQuery();
    // _query->addQueryItem("version", VERSION);
    // _url->setQuery(_query);

    Just removing the // before "#include <QUrlQuery>" in my .h file causes the build to fail, with errors pointing to inside qurlquery.h.

    In the qurlquery.h file:
    inline void QUrl::setQueryItems(const QList<QPair<QString, QString> > &qry)
    { QUrlQuery q(*this); q.setQueryItems(qry); setQuery(q); }
    inline void QUrl::addQueryItem(const QString &key, const QString &value)
    { QUrlQuery q(*this); q.addQueryItem(key, value); setQuery(q); }
    inline QList<QPair<QString, QString> > QUrl::queryItems() const
    { return QUrlQuery(*this).queryItems(); }
    inline bool QUrl::hasQueryItem(const QString &key) const
    { return QUrlQuery(*this).hasQueryItem(key); }@

    I appreciate your help, by the way. This seems like a tricky error to debug, and I'm honestly completely lost.

  • First search in your complete source code for QUrl implementations and remove it.

    • cmd + F
    • Advanced
    • search for url

    Then to delete your complete build folder and then do qmake and build.

    At least you could try to use another qt version. Like qt 5.3.2 or 5.4 !

Log in to reply