Unsolved undefined reference to `QQuickTextControl::textCursor() const'
-
I find myself in a situation that I need to tap into the private implementations of a few classes, but the code doesn't compile, complaining about undefined references.
QQuickTextControl
is a stock framework class, so it is definitely defined, but for some reason the linker cannot pick it up.I have already added
quick-private
to the PRO file.Is there something else that I need to do to get it to compile?
-
Hi,
From a quick look at Qt's sources, that class comes from the
QtDeclarative
module. -
@SGaist Hmm, if that's the case how come the header is in
QtQuick/private/qquicktextcontrol_p.h
?
Come to think about it, I don't even seem to have the declarative module at all. Besides, if it came from declarative, wouldn't it be named
QDeclarativeTextControl
instead?Anyway, to elaborate a little further on the issue at hand, I want to expose some text cursor operations to QML which are currently not part of the public API, my code is rather simple:
#include <QtQuick/private/qquicktextedit_p.h> #include <QtQuick/private/qquicktextedit_p_p.h> #include <QtQuick/private/qquicktextcontrol_p.h> class CTextEdit : public QQuickTextEdit { Q_OBJECT public: CTextEdit(QQuickItem * p = 0) : QQuickTextEdit(p) {} public slots: void cursorOp(int mode) { QQuickTextEditPrivate * ep = reinterpret_cast<QQuickTextEditPrivate *>(d_ptr.data()); QTextCursor c = ep->control->textCursor(); c.movePosition((QTextCursor::MoveOperation)mode); ep->control->setTextCursor(c); } };
Yet I get undefined reference errors for the
control
functions:moc_extra.cpp:-1: error: undefined reference to `QQuickTextControl::textCursor() const' moc_extra.cpp:-1: error: undefined reference to `QQuickTextControl::setTextCursor(QTextCursor const&)'
So how do I get it to build?
-
What version of Qt are you using ?
-
@SGaist Latest 5.9.1
-
I've successfully built it with 5.9.2.
-
@SGaist Did you have to do anything particular?
-
Nothing special, the only difference I can see is that it's a self-built Qt but that shouldn't matter.
-
@SGaist Only using
quick-private
?It has been a while since I was able to get a successful Qt build, but I only do static custom builds, and that hasn't work since 5.8 and the "build system (so called) improvements"...
-
Yes, only with it.
However, I'm not using a static build but that shouldn't change anything.
What platform are you on ?
-
@SGaist It is the "stock" Qt pre-build, on windows 7 with mingw, dynamic linking and so on.
This is certainly odd.
-
@SGaist Installed the latest 5.9.2 snapshot, still getting the same errors...
I also tried building it into a new empty project rather than my production project, still a no-go.
Are you sure that you actually build it? Like in "register it as a QML type and see if it works".
-
I pasted your code in a main.cpp and instantiated an object from it and called the slot.
If you want more testing then provide a complete minimal buildable example.
One thing I saw with my build is that I still have the declarative sources in my git tree so it got built which might explain why I'm succeeding.
-
@SGaist Well, I'll give a barebone build a try and see if it makes a difference.
However, it says that:
All classes that were previously in the QtDeclarative module have been moved into the Qt QML and Qt Quick modules
So maybe it is a bug of some sort?
-
@SGaist I built Qt from source, declarative was definitely built.
Still the same errors.
-
I'd try to check the resulting libraries to see which one contains the missing symbols.
-
OK, there has been some development, amazingly, I actually managed to get the first successful static Qt build since January. AND that code compiled successfully.
It is strange that it didn't compile with an identical configuration save for the static flag.
This actually works for me only in the context of development, which I do on windows. But it is an android app, and it still doesn't build on the stock Qt android build.
However, rather than getting unresolved reference errors, I get a
collect2.exe:-1: error: error: ld returned 1 exit status
Commenting out the cursorOp() function and it builds successfully.
It would seem that I'd have to also do a custom Qt build for android, something I haven't done and something I am certainly not looking forward to do, as every different platform has its new set of quirks and associated headaches.
-
-
Thanks for the link