[Openstreetmap-dev] Hacking osm-editor (warning c++ newbie)

Nick Whitelegg Nick.Whitelegg at solent.ac.uk
Fri Sep 23 17:54:51 BST 2005


      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





More information about the dev mailing list