Results 1 to 6 of 6

Thread: Error Trying to take out a qlist from a binary file

  1. #1
    Join Date
    May 2007
    Posts
    131
    Thanks
    17
    Thanked 4 Times in 2 Posts

    Default Error Trying to take out a qlist from a binary file

    Qt Code:
    1. QDataStream& operator>>(QDataStream &out, car *&list)
    2. {
    3. QString w,x,y,z;
    4. out>>w;
    5. out>>x;
    6. out>>y;
    7. out>>z;
    8. out>>list->register; //<--- the line who dont run according to the debugger but i dont know why, this is my qlist
    9. list->plate=w;
    10. list->brand=x;
    11. list->mileage=y.toDouble();
    12. list->cylinder_capacity=z.toDouble();
    13. return out;
    14. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by bmn; 17th September 2014 at 04:13.

  2. #2
    Join Date
    May 2012
    Location
    Bangalore, India
    Posts
    271
    Thanks
    29
    Thanked 50 Times in 47 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Error Trying to take out a qlist from a binary file

    You have to provide the definition of the datatype car, then only we will get to know about the main problem.
    Heavy Metal Rules. For those about to rock, we salute you.
    HIT THANKS IF I HELPED.

  3. #3
    Join Date
    May 2007
    Posts
    131
    Thanks
    17
    Thanked 4 Times in 2 Posts

    Default Re: Error Trying to take out a qlist from a binary file

    I already do that but I don't why is keeping doing the same error when i tried to read te binary file

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Error Trying to take out a qlist from a binary file

    Why are you using a reference to a pointer as second argument to operator >> ? This is how such method looks like most of the time:
    Qt Code:
    1. QDataStream & operator>>(QDataStream & in, MyClass & obj){
    2. ...
    3. return in;
    4. }
    To copy to clipboard, switch view to plain text mode 
    What kind of error do you get ? Is your pointer null ?

  5. #5
    Join Date
    May 2007
    Posts
    131
    Thanks
    17
    Thanked 4 Times in 2 Posts

    Default Re: Error Trying to take out a qlist from a binary file

    It doesn't even run, when my program starts is looking for the file and found it but when i tries do put the qlist inside my instance of qlist don't work
    here is the code where I read
    Qt Code:
    1. QFile read("register.txt");
    2. if(read.exists()){
    3. if (read.open(QIODevice::ReadOnly)){;
    4. QDataStream in(&read);
    5. in.setVersion(QDataStream::Qt_4_6);
    6. in >> cars;
    7. read.close();
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 
    cars is my list in the main (QList<car> cars)

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Error Trying to take out a qlist from a binary file

    this is my qlist: car *&list
    This is not a QList<car>. It isn't even a QList< car * >. It is a reference to a pointer to a "car" instance. So calling "in >> cars" can't possibly call this method if "cars" is actually a QList<car>, because the QDataStream operator you have defined doesn't match the required function signature.

    So what does your code really look like? What you have posted isn't complete enough.

Similar Threads

  1. Binary QFile error
    By Affenbrotbaum in forum Newbie
    Replies: 3
    Last Post: 29th January 2010, 02:13
  2. How to write a QList into a binary file?
    By Lawand in forum Qt Programming
    Replies: 23
    Last Post: 15th June 2009, 10:04
  3. Read binary from file
    By weldpua2008 in forum Newbie
    Replies: 2
    Last Post: 3rd April 2009, 23:50
  4. cannot execute binary file
    By mgturner in forum Installation and Deployment
    Replies: 1
    Last Post: 16th March 2009, 17:04
  5. How to Print a doc file (or binary file) to printer
    By rmagro in forum Qt Programming
    Replies: 15
    Last Post: 5th September 2008, 15:46

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.