Results 1 to 4 of 4

Thread: Using STL in Qt4 vs. Qt3

  1. #1
    Join Date
    Oct 2007
    Posts
    11
    Thanks
    4

    Default Using STL in Qt4 vs. Qt3

    Hi,

    This shows my ignorance, but in Qt3 I could do:

    Qt Code:
    1. // Find the latest mtime...
    2. for (vector<string>::const_iterator iss = new_partitions->begin(); iss != new_partitions->end(); ++iss) {
    3. QString this_string = (*iss);
    To copy to clipboard, switch view to plain text mode 

    to which I get an error:

    Qt Code:
    1. do_test_gpc.cpp:323: error: conversion from 'const std::basic_string<char, std::char_traits<char>, std::allocato
    2. r<char> >' to non-scalar type 'QString' requested
    To copy to clipboard, switch view to plain text mode 

    Could someone point out what should be done instead?
    Thanks!

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Using STL in Qt4 vs. Qt3

    In Qt 4 you have QString::fromStdString().
    J-P Nurmi

  3. #3
    Join Date
    Oct 2007
    Location
    Munich, Bavaria
    Posts
    144
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using STL in Qt4 vs. Qt3

    In Qt4 implicit convertion from std::string to QString is no longer supported.
    You need to make use of QString QString::fromStdString ( const std::string & str )

    Instead of :
    Qt Code:
    1. ...
    2. QString this_string = (*iss);
    3. ...
    To copy to clipboard, switch view to plain text mode 
    You need to write:
    Qt Code:
    1. ...
    2. QString this_string = QString::fromStdString(*iss);
    3. ...
    To copy to clipboard, switch view to plain text mode 

  4. The following user says thank you to DeepDiver for this useful post:

    hvw59601 (4th November 2007)

  5. #4
    Join Date
    Oct 2007
    Posts
    11
    Thanks
    4

    Default Re: Using STL in Qt4 vs. Qt3

    Thanks a lot!!

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.