d
dufusJuly 24, 2018, 6:24 a.m.

Копирует пустой файл.

с++, GPX, COPY

У меня копируется пустой файл. Хотя до копирования я его создаю и наполняю содержимым.

Мой код:
void CreateTrack::XmlStreamWriter()
{
    QDate Date = Date.currentDate();
    QString DateString = Date.toString("dd-MM-yy");
    if (QDir(QDir::currentPath()+"/Temp/").exists() == false) {
        QDir().mkpath(QDir::currentPath()+"/Temp/");
    }
    QString NameFile = QDir::currentPath()+"/Temp/Маршр. точки_"+DateString+".gpx";
    QFile file(NameFile);
    if(file.open(QIODevice::WriteOnly | QIODevice::Append))
    {
        QXmlStreamWriter writer( &file );
        writer.setCodec("UTF-8");
        writer.writeStartDocument("1.0",false);
        writer.writeStartElement("gpx");
        writer.writeAttribute(QXmlStreamAttribute("xmlns", "http://www.topografix.com/GPX/1/1"));
        writer.writeAttribute(QXmlStreamAttribute("xmlns:gpxx", "http://www.garmin.com/xmlschemas/GpxExtensions/v3"));
        writer.writeAttribute(QXmlStreamAttribute("xmlns:wptx1", "http://www.garmin.com/xmlschemas/WaypointExtension/v1"));
        writer.writeAttribute(QXmlStreamAttribute("xmlns:gpxtpx", "http://www.garmin.com/xmlschemas/TrackPointExtension/v1"));
        writer.writeAttribute(QXmlStreamAttribute("creator", "GPSMAP 64st"));
        writer.writeAttribute(QXmlStreamAttribute("version", "1.1"));
        writer.writeAttribute(QXmlStreamAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"));
        writer.writeAttribute(QXmlStreamAttribute("xsi:schemaLocation", "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www8.garmin.com/xmlschemas/GpxExtensionsv3.xsd http://www.garmin.com/xmlschemas/TrackStatsExtension/v1 http://www8.garmin.com/xmlschemas/TrackStatsExtension.xsd http://www.garmin.com/xmlschemas/WaypointExtension/v1 http://www8.garmin.com/xmlschemas/WaypointExtensionv1.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd"));

            writer.writeStartElement("metadata");
                writer.writeStartElement("link");
                writer.writeAttribute(QXmlStreamAttribute("href", "http://www.garmin.com"));
                    writer.writeTextElement("text","Garmin International");
                writer.writeEndElement();          
                QDateTime DateTime = DateTime.currentDateTime();
                QString DateTimeString = DateTime.toString("yyyy-MM-ddThh:mm:ssZ");
                writer.writeTextElement("time",DateTimeString);
            writer.writeEndElement();

            CreateTrack::XmlStreamWriterElement(writer);

        writer.writeEndElement();
        writer.writeEndDocument();
    }

    bool Garmin = false;

    foreach (const QStorageInfo &storage, QStorageInfo::mountedVolumes()) {
        if (!storage.isReadOnly()) {
            QString GPX = "Garmin/GPX";
            if (QDir(storage.rootPath()+GPX).exists() == true) {
                qDebug()<<storage.rootPath()+GPX+"/"+QFileInfo(NameFile).fileName();
                qDebug()<<NameFile;
                QFile::copy(NameFile,storage.rootPath()+GPX+"/"+QFileInfo(NameFile).fileName());
                //QFile::remove(NameFile);
                Garmin = true;
                msgBox.setText("Трек добавлен.");
                msgBox.exec();
                this->close();

            } else {
                //msgBox.setText("Устройство GARMIN не найдено.");
                //msgBox.exec();
            }
        }
    }

    if (Garmin == false) {
        //QFile::remove(NameFile);
        msgBox.setText("Устройство GARMIN не найдено.");
        msgBox.exec();
    }

    return;

}

void CreateTrack::XmlStreamWriterElement(QXmlStreamWriter& writer)
{
    for (int i=1;i<ModelPoint->rowCount();i++) {
        writer.writeStartElement("wpt");
        writer.writeAttribute(QXmlStreamAttribute("lat", ModelPoint->index(i,0).data().toString().replace(",",".")));
        writer.writeAttribute(QXmlStreamAttribute("lon", ModelPoint->index(i,1).data().toString().replace(",",".")));
        QDateTime DateTime = DateTime.currentDateTime();
        QString DateTimeString = DateTime.toString("yyyy-MM-ddThh:mm:ssZ");
        writer.writeTextElement("time", DateTimeString);
        writer.writeTextElement("name", ModelPoint->index(i,2).data().toString());
        writer.writeTextElement("sym", "Flag, Blue");
        writer.writeEndElement();
    }
}
В результате получается файл Маршр. точки_24-07-18.gpx:
<?xml version="1.0" encoding="UTF-8" standalone="no"?><gpx xmlns="http://www.topografix.com/GPX/1/1" xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3" xmlns:wptx1="http://www.garmin.com/xmlschemas/WaypointExtension/v1" xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" creator="GPSMAP 64st" version="1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www8.garmin.com/xmlschemas/GpxExtensionsv3.xsd http://www.garmin.com/xmlschemas/TrackStatsExtension/v1 http://www8.garmin.com/xmlschemas/TrackStatsExtension.xsd http://www.garmin.com/xmlschemas/WaypointExtension/v1 http://www8.garmin.com/xmlschemas/WaypointExtensionv1.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd"><metadata><link href="http://www.garmin.com"><text>Garmin International</text></link><time>2018-07-24T13:04:46Z</time></metadata><wpt lat="55.701" lon="37.5572"><time>2018-07-24T13:04:46Z</time><name>photo03 — копия.jpg</name><sym>Flag, Blue</sym></wpt><wpt lat="60.049883" lon="30.352043"><time>2018-07-24T13:04:46Z</time><name>ПРОБА 0</name><sym>Flag, Blue</sym></wpt><wpt lat="60.049913" lon="30.352396"><time>2018-07-24T13:04:46Z</time><name>Проба 1</name><sym>Flag, Blue</sym></wpt><wpt lat="60.05" lon="30.35"><time>2018-07-24T13:04:46Z</time><name>ПРОБА 5555</name><sym>Flag, Blue</sym></wpt></gpx>
А в GARMIN отправляется пустой файл Маршр. точки_24-07-18.gpx


Маршр._точки_24-07-18.gpx
We recommend hosting TIMEWEB
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.

Do you like it? Share on social networks!

1
Evgenii Legotckoi
  • July 24, 2018, 8:28 a.m.
  • (edited)

Добрый день!

Не вижу, чтобы вы делали flush() и close() файла по окончанию записи.
Описание метода flush()
Flushes any buffered data to the file. Returns true if successful; otherwise returns false .

что означает, что данные записываются в файл. Полагаю, что ваши данные остаются в буффере, и окончательно не записываются в файл.
добавьте строки
file.flush();
file.close();

После работы XML Writer
Возможно из-за этого и не работает





    Comments

    Only authorized users can post comments.
    Please, Log in or Sign up
    AD

    C ++ - Test 004. Pointers, Arrays and Loops

    • Result:50points,
    • Rating points-4
    m

    C ++ - Test 004. Pointers, Arrays and Loops

    • Result:80points,
    • Rating points4
    m

    C ++ - Test 004. Pointers, Arrays and Loops

    • Result:20points,
    • Rating points-10
    Last comments
    i
    innorwallNov. 15, 2024, 8:26 a.m.
    Qt/C++ - Lesson 031. QCustomPlot – The build of charts with time buy generic priligy We can just chat, and we will not lose too much time anyway
    i
    innorwallNov. 15, 2024, 6:03 a.m.
    Qt/C++ - Lesson 060. Configuring the appearance of the application in runtime I didnt have an issue work colors priligy dapoxetine 60mg revia cost uk August 3, 2022 Reply
    i
    innorwallNov. 14, 2024, 11:07 p.m.
    Circuit switching and packet data transmission networks Angioedema 1 priligy dapoxetine
    i
    innorwallNov. 14, 2024, 10:42 p.m.
    How to Copy Files in Linux If only females relatives with DZ offspring were considered these percentages were 23 order priligy online uk
    i
    innorwallNov. 14, 2024, 8:09 p.m.
    Qt/C++ - Tutorial 068. Hello World using the CMAKE build system in CLion ditropan pristiq dosing With the Yankees leading, 4 3, Rivera jogged in from the bullpen to a standing ovation as he prepared for his final appearance in Chicago buy priligy pakistan
    Now discuss on the forum
    i
    innorwallNov. 14, 2024, 2:39 p.m.
    добавить qlineseries в функции priligy amazon canada 93 GREB1 protein GREB1 AB011147 6
    i
    innorwallNov. 11, 2024, 9:55 p.m.
    Всё ещё разбираюсь с кешем. priligy walgreens levitra dulcolax carbs The third ring was found to be made up of ultra relativistic electrons, which are also present in both the outer and inner rings
    9
    9AnonimOct. 25, 2024, 7:10 p.m.
    Машина тьюринга // Начальное состояние 0 0, ,<,1 // Переход в состояние 1 при пустом символе 0,0,>,0 // Остаемся в состоянии 0, двигаясь вправо при встрече 0 0,1,>…

    Follow us in social networks