Hacking osm-editor (warning c++ newbie)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Hacking osm-editor (warning c++ newbie)

Alex Willmer
Evening all,

I've been trying out the latest osm-editor, seems to be just the ticket.

There was one aspect that bugged me. To save a _lot_ of space my gpx
files are all gzipped (eg track-20050101,gpx.gz). It would be nice if
osm-editor could read them directly, rather than needing to gunzip them
myself.

With this in mind I made some tentative edits to MainWindow.cpp, diff is
attached.

Frankly, this is my first ever c++ code beyond "Hello World!" and I'm
sure it shows. Most of it is an educated guess, some is shooting blind.

My compilation is bombing out at line 402, when I try to pass a QBuffer
to the constructor of QXmlInputSource. I've tried decorating the qbuf
argument with &/* but those are obviously also wrong.

I'd just like to know, am I on the right track, even to produce a memory
leaking, but functioning hack. Or is this a complete WTF?

Thanks

Alex

Here is the compilation error I'm receiving:

c++ -w -g -I/usr/include/qt3 `curl-config --cflags` -I/usr/local/include
-Ijeeps-0.1.4-nick   -c -o MainWindow.o MainWindow.cpp
MainWindow.cpp: In member function `OpenStreetMap::Components*
   OpenStreetMap::MainWindow::doOpen(const QString&, bool)':
MainWindow.cpp:398: error: no matching function for call to
`QXmlInputSource::
   QXmlInputSource(QBuffer&)'
/usr/include/qt3/qxml.h:154: error: candidates are:
   QXmlInputSource::QXmlInputSource(const QXmlInputSource&)
/usr/include/qt3/qxml.h:159: error:
   QXmlInputSource::QXmlInputSource(QTextStream&)
/usr/include/qt3/qxml.h:158: error:
   QXmlInputSource::QXmlInputSource(QFile&)
/usr/include/qt3/qxml.h:157: error:
   QXmlInputSource::QXmlInputSource(QIODevice*)
/usr/include/qt3/qxml.h:156: error:
   QXmlInputSource::QXmlInputSource()
MainWindow.cpp:402: error: `source' undeclared (first use this function)
MainWindow.cpp:402: error: (Each undeclared identifier is reported only
once
   for each function it appears in.)
make: *** [MainWindow.o] Error 1



_______________________________________________
Openstreetmap-dev mailing list
[hidden email]
http://bat.vr.ucl.ac.uk/cgi-bin/mailman/listinfo/openstreetmap-dev

MainWindow.cpp.diff (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Hacking osm-editor (warning c++ newbie)

Nick Whitelegg-2

      QXmlInputSource  source;
+     if (filename.endsWith(".gpx"))
+     {
+           QFile file(filename);
+           source = QXmlInputSource (&file);
+     }
+     else if (filename.endsWith(".gpx.gz"))
+     {
+           gzFile file;
+           char buf[16384];
+           int len;
+           int err;
+           QCString tmp("");
+
+           file = gzopen(filename, "rb");
+           while (gzread(file, buf, sizeof(buf)) > 0)
+           {
+                 tmp.append(buf);
+           }
+           QBuffer qbuf(tmp);
            // Address of as the constructor takes a pointer to a QIODevice
+           source = QXmlInputSource(&qbuf);
+     }

      QXmlSimpleReader reader;
      reader.setContentHandler(&parser);

Alex,

The main problem was that you were declaring the QXmlInputSource inside the "if" and "else if" blocks, meaning the variable
was local to the if and else if blocks, i.e. it can not be used outside the "if" and "else if". Also the QXmlInputSource constructor
takes a pointer to a QIODevice, so you need an & symbol. The above code incorporates both those changes.

Nick


_______________________________________________
Openstreetmap-dev mailing list
[hidden email]
http://bat.vr.ucl.ac.uk/cgi-bin/mailman/listinfo/openstreetmap-dev