Results 1 to 5 of 5

Thread: reading JSON file in Qt5

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2013
    Posts
    8
    Qt products
    Qt5
    Platforms
    MacOS X

    Default reading JSON file in Qt5

    Hi,

    I have been trying to figure out how to read a JSON file using Qt5 QJsonDocument with no success so far.
    I can't find any examples online. If someone could give me a simple example I would appreciate it.

    Here is my code::
    Qt Code:
    1. QFile file;
    2. file.setFileName("/tmp/settings.json");
    3. file.open(QIODevice::ReadOnly | QIODevice::Text);
    4. QJsonDocument settdoc;
    5. settdoc.fromBinaryData(file.readAll());
    6. qDebug() << settdoc.isNull();
    To copy to clipboard, switch view to plain text mode 

    settdoc.isNull() returns true, I can read the file into a stream without any issue and I validated the json as well.

    Thank you

    Laszlo
    Last edited by Lykurg; 18th January 2013 at 07:40. Reason: missing [code] tags

Similar Threads

  1. Using external Json file in QML
    By Kelteseth in forum Qt Quick
    Replies: 0
    Last Post: 30th November 2012, 17:08
  2. Reading XML file into a data file correctly?
    By falconium in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2011, 18:55
  3. Reading XML file using DOM
    By rk0747 in forum Qt Programming
    Replies: 6
    Last Post: 4th February 2010, 22:09
  4. help in reading XML file
    By cshiva_in in forum Qt Programming
    Replies: 1
    Last Post: 24th March 2008, 13:55
  5. reading from a file
    By mickey in forum General Programming
    Replies: 32
    Last Post: 19th July 2007, 01:04

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.