1

Why is a TextArea with

wrapMode: TextEdit.NoWrap 

always causing

file:///C:/Qt/5.5/mingw492_32/qml/QtQuick/Controls/ScrollView.qml:340:13: QML Item: Possible anchor loop detected on fill.

when I run it?

I am running Qt 5.5 on a 64-bit Windows 7 machine, and compiling with MinGW.

Here is my QML code test.qml:

import QtQuick 2.4
import QtQuick.Controls 1.3

ApplicationWindow {
    title: "test window"
    width: 500
    height: 500
    visible: true

    TextArea {
        wrapMode: TextEdit.NoWrap
    }
}

Here is my C++ code main.c:

#include <QApplication>
#include <QQmlApplicationEngine>
#include <QtQml>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/test.qml")));

    return app.exec();
}

Even if I add anchors.fill: parent to the TextArea, I still get the warnings.

As a second part of this question, is this warning something I should be worried about, or is it something I can safely ignore?

BaCaRoZzo
  • 7,502
  • 6
  • 51
  • 82
  • Obviously this question is not related to `C++`, please, next time don't put `c++` tag on questions like this. In this question you may even remove your `main.c` because it does nothing but loads your QML and the question is about `qml`-behaviour. – VP. Jul 11 '15 at 17:31
  • I'm new to Qt and didn't know if the way of launching the qml file might affect it in some way I don't understand. Next time I will remember to limit the information I give. –  Jul 11 '15 at 17:34
  • In this case your `c++` is not needed. Also, your question requires an answer about `QML` but not `c++`. I'd suggest you to remove your `c++` code snippet, information about OS and compiler because it is unnecessary in this case. – VP. Jul 11 '15 at 17:37
  • Your TextArea doesn't have a size specified, so it's not clear what the expected behavior would be in this situation. What happens if you either assign dimensions or anchors to the TextArea? – MrEricSir Jul 11 '15 at 17:57
  • @MrEricSir Originally I had some more things like a button above it, and then i anchored it to the left, right, and bottom of the parent, and the top of the text box was anchored to the bottom of the button, but I still got that error. So for the example, I tried removing anything unnecessary. If ony my example I add `anchors.fill: parent` to the TextArea, it still gives the error. –  Jul 11 '15 at 18:14
  • 1
    I'm tempted to say that the warning being printed is a bug.. it probably shouldn't happen. – Mitch Jul 11 '15 at 19:31
  • It even gets worse if you add text and exceed the current viewport (with or without `width`/`height` set). Removing the offending row solves the problem. Uhm, I agree with @Mitch about that. I wish you long life and good health 'cos you found a bug! :) – BaCaRoZzo Jul 11 '15 at 20:17

1 Answers1

1

I think it's a bug from Qt, you can ignore it. When created, TextArea have a width != 0, even if it's empty. When you enter a text that have an implicitWidth smaller then the (default) width of the TextArea, you will get this warning.

A workaround is to assign the wrapMode property in the Component.onCompleted handler:

Component.onCompleted: wrapMode = TextEdit.NoWrap
BaCaRoZzo
  • 7,502
  • 6
  • 51
  • 82
Mido
  • 1,092
  • 1
  • 9
  • 14
  • 2
    I think it's an issue deeper than a `width` issue (even if setting/not setting `width` can greatly effect the warning). Anyhow, filed a bug - [QTBUG-47167](https://bugreports.qt.io/browse/QTBUG-47167). – BaCaRoZzo Jul 12 '15 at 06:36