[Solved] QXmlNodeModelIndex::stringValue link failure under Linux
-
Hi there,
I have a Qt 5.2.1 project that I compile with Gcc under Windows and Linux. Everything works for Windows, however, the executable won't link under Linux. In both cases I will get the following warning:
inline function 'QString QXmlNodeModelIndex::stringValue() const' used but never defined [enabled by default]
This links and works for Windows, but for Linux I get:
undefined reference to 'QXmlNodeModelIndex::stringValue() const'
The Cmake projects requires Qt5XmlPatterns with FIND_PACKAGE(Qt5XmlPatterns REQUIRED)
and links the lib with QT5_USE_MODULES(${TARGET} Core Sql Network Xml XmlPatterns)I wrote a sample application using qmake to reproduce the problem:
main.pro:
@
CONFIG += qt debug
SOURCES += main.cpp
QT += xmlpatterns
@main.cpp:
@
#include <QCoreApplication>
#include <QBuffer>
#include <QXmlQuery>
#include <QXmlResultItems>
#include <QXmlItem>
#include <iostream>int main(int argc, char **argv)
{
QCoreApplication app( argc, argv );
QBuffer buffer;
buffer.open(QIODevice::ReadWrite);
buffer.write("<?xml version="1.0"?>");
buffer.write("<element><sub>a</sub><sub/></element>");
buffer.seek(0);
QXmlQuery query;
query.setFocus( &buffer );
query.setQuery("//element/sub");
QXmlResultItems results;
query.evaluateTo( &results );
QXmlItem item = results.next();
while( !item.isNull() ) {
if( item.isNode() ) {
std::cout << "Found node " << item.toNodeModelIndex().stringValue().toStdString() << std::endl;
}
item = results.next();
}
buffer.close();
}
@Works under Windows:
@
$./main.exe
Found node a
Found node
@Fails to link under Linux:
@
g++ -Wl,-rpath,/opt/Qt/5.2.1/gcc_64 -Wl,-rpath,/opt/Qt/5.2.1/gcc_64/lib -o main main.o -L/opt/Qt/5.2.1/gcc_64/lib -lQt5XmlPatterns -lQt5Network -lQt5Gui -lQt5Core -lGL -lpthread
main.o: In functionmain': /home/ukoehler/devel/QtProblems/ModelNodeIndex_stringValue/main.cpp:24: undefined reference to
QXmlNodeModelIndex::stringValue() const'
collect2: error: ld returned 1 exit status
@Any help would be greatly appreciated.
Uwe Köhler
-
Hi and welcome to devnet,
What surprises me is that it works on windows. The documentation from QXmlNodeModelIndex doesn't mention any stringValue() function
-
Many thanks for your reply. The member stringValue() is inherited from QAbstractXmlNodeModel. I nosed around the source code and couldn't find any implementation of the function (obviously didn't look long enough).
Is this a bug? Should I commit a bug report?
Cheers
Uwe Köhler
-
AFAIK, QXmlNodeModelIndex doesn't inherit from QAbstractXmlNodeModel. However, you can use it with stringValue from QAbstractXmlNodeModel.
e.g.
@
QXmlNodeModelIndex index = item.item.toNodeModelIndex();
qDebug() << model->stringValue(index);
@So it's strange that it's working on windows.
-
Ah, the QXmlNodeModelIndex file just includes qabstractxmlnodemodel.h and there I can find the public member inline QString QXmlNodeModelIndex::stringValue() const. But you are absolutely correct, it is not derived from QAbstractXmlNodeModel.
Well, Eclipse showed that the member exists, but didn't show the comment above that:
@
/* The members below are internal, not part of the public API, and- unsupported. Using them leads to undefined behavior. */
@
Many thanks for your help. Didn't see that without you pointing me in the right direction.
- unsupported. Using them leads to undefined behavior. */
-
You're welcome !
I still find strange that you can actually use them on Windows and not on linux, there might be something fishy.
If you want to know more about it, you can ask on the interest mailing list. You'll find Qt's developers/maintainers there (this forum is more user oriented)
-
@SGaist Hi Sam,
I get the similar problem while using stringValue(). Looks like it is not implemented.
Is there anyway to overcome this?
Thanks!
-
Hi,
It's an internal function of QXmlNodeModelIndex and from the looks of it, unused and not implemented.
AFAICS, you should use the model stringValue method to get the data from the index.
-
@SGaist Thanks for the clarification Sam..