添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode . Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

Hello there,
i got some problems with the QMapPolygon.
I add coordinates manually (using a mouse area) this works fine (i can see the Polygon), i then give these coordinates to cpp and save them to a file. Fine this works smoothly too, but if i want to load these coordinates from the file, give them to QML and add them to the MapPolygon i got some problems.
I am using QMap to display the map and the map plugin from here maps
I hope you can help me

My .txt file with the coordinates looks like this:
48° 11' 49.7" N, 10° 22' 43.2" E
48° 1' 55.6" N, 11° 3' 55.1" E
48° 17' 58.4" N, 11° 1' 16.9" E
48° 44' 49.4" N, 10° 40' 11.3" E
48° 49' 10.0" N, 10° 18' 45.9" E
48° 37' 12.5" N, 10° 5' 15.1" E
48° 18' 51.0" N, 10° 5' 34.8" E

The relevant code in Cpp:

/void Coords::getfromFile()
    QFile file("out.txt");
    file.open(QIODevice::ReadOnly | QIODevice::Text);
    QTextStream out(&file);
    QString text;
    liste.clear();
    while ( !out.atEnd() )
    text = out.readLine();
    liste.append(text);               //liste is  QList<QString> liste
    file.close();
    if(liste.isEmpty()==true)
        qDebug() << "Error File empty";
    emit getfromSignal(liste,liste.length());

The relevant QML part:

Button{
                id: loadPolygon
                text: "Load Markers"
                anchors.right: parent.right
                anchors.top: savePolygon.bottom
                onClicked:
                    coords.getfromFile()      //here the cpp function gets called
            Connections {
                    id:cppConnection
                    target: coords
                    ignoreUnknownSignals: true
                    onSavetoSignal: {
                        savePolygon.visible = false
                    onGetfromSignal: {
                        var path = list     //list is the QList liste from cpp 
                        var i = 0
                        console.log(length)     //length is the liste.length() from cpp
                        for(i;i<(length-2);i++)
                            console.log(i)
                            console.log(path[i])
                            polygon.addCoordinate(path[i])
                        polygon.path = path
                        console.log(path[0])
                        console.log(path[1])
                        console.log(path[2])
                        polygon.visible = true

The code compiles without errors but when i try to execute i always get some outputs from the console like this:
qml: 7
qml: 0
qml: 48° 11' 49.7" N, 10° 22' 43.2" E
qml: 1
qml: 48° 1' 55.6" N, 11° 3' 55.1" E
qml: 2
qml: 48° 17' 58.4" N, 11° 1' 16.9" E
qml: 3
qml: 48° 44' 49.4" N, 10° 40' 11.3" E
qml: 4
qml: 48° 49' 10.0" N, 10° 18' 45.9" E
qml: 48° 11' 49.7" N, 10° 22' 43.2" E
qml: 48° 1' 55.6" N, 11° 3' 55.1" E
qml: 48° 17' 58.4" N, 11° 1' 16.9" E
QPainterPath::addRect: Adding rect where a parameter is NaN or Inf, ignoring call

from then the console keeps logging
QPainterPath::addRect: Adding rect where a parameter is NaN or Inf, ignoring call
if i move the map or anything.

You guys have any ideas what i should change?

thanks guys.

@Gigamens So I haven't used QML before (purely C++ side of Qt), but from what I looked at your coordinates from the file are not in a format that you can just pass into polygon.path.

From the docs it looks like you need something like:

Location {
    coordinate {
        latitude: -27.5
        longitude: 153.1

There are no allowances that I can see for things like the degree symbol, or ' or ". Likewise I don't see any indicators for directions like N/E/etc. Those seem to be handled with negatives numbers.

So my guess is you are feeding bad data into the path. Try using the input that it expects and save your files using those values.

I may be totally off base here since I don't use QML though. ;)