Results 1 to 7 of 7

Thread: QString assignment problem in C++ style but not in C style

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2009
    Posts
    122
    Thanks
    74
    Qt products
    Qt4
    Platforms
    Windows

    Question QString assignment problem in C++ style but not in C style

    Hi,

    This C++ does not work:
    Qt Code:
    1. string line;
    2. getline (INfile,line);
    3. QString Line = line;
    To copy to clipboard, switch view to plain text mode 
    error: conversion from ‘std::string’ to non-scalar type ‘QString’ requested

    However this C style does work:
    Qt Code:
    1. char line[50]="";
    2. fgets(line, 50, INfile);
    3. QString Line = line;
    To copy to clipboard, switch view to plain text mode 

    Why is that? I'd really like to get the C++ style to work. What's the best way to obtain a line from a file in Qt?

    Thanks!!
    Last edited by timmu; 29th December 2011 at 13:56.

Similar Threads

  1. copy constructor and assignment operator
    By sajis997 in forum Newbie
    Replies: 9
    Last Post: 27th July 2011, 17:02
  2. QSettings Assignment
    By SixDegrees in forum Qt Programming
    Replies: 1
    Last Post: 30th April 2010, 23:00
  3. QString assignment
    By valgaba in forum Qt Programming
    Replies: 4
    Last Post: 25th April 2010, 17:31
  4. QVector assignment question
    By hvw59601 in forum Qt Programming
    Replies: 1
    Last Post: 14th November 2007, 20:34
  5. copying and assignment constructors
    By TheKedge in forum General Programming
    Replies: 3
    Last Post: 17th August 2006, 15:09

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.