Results 1 to 3 of 3

Thread: Problem with QDir::mkdir() and vector of QStrings

  1. #1
    Join Date
    Jun 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Problem with QDir::mkdir() and vector of QStrings

    I have a problem with QDir::mkdir().

    I have a vector of QStrings and would like to make a new directory (in a given folder) named off of one of the QStrings in the vector, however, it fails to do so. Code:

    Qt Code:
    1. QDir dir(/*path*/);
    2. QString newPath = rawData[ 9 ];// rawData is the vector of QStrings
    3. dir.mkdir( newPath );
    To copy to clipboard, switch view to plain text mode 

    When I output newPath, everything is okay, yet Qdi::mkdir fails for no apparent reason. T_T

    Any help would be greatly appreciated.

  2. #2
    Join Date
    May 2011
    Posts
    239
    Thanks
    4
    Thanked 35 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: Problem with QDir::mkdir() and vector of QStrings

    Even though there is no apparent reason, apparently there is a reason... It might be something hard to notice, like a trailing newline or other invisible character -- which is why people should always post some more code than where the problem exhibits. It is a question of how the variable & data has been created.

  3. #3
    Join Date
    Jun 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with QDir::mkdir() and vector of QStrings

    No, I have outputed rawData[9] as well, whilst debugging, and it is exactly what it should be. In fact I have outputted the entire vector, and everything is correct. If you would like me to post some more code then sure. : )

    I input into the vector with this function:

    Qt Code:
    1. signed int FileSystem::readFromFile(){
    2. std::string tmp = selectedFilePath.toStdString();//selectedFilePath is a QString of file path I am going to read. It is initalized else where in the program.
    3. std::ifstream ifs;
    4. ifs.open( tmp.c_str() );
    5. if( ifs.is_open() ){
    6. while( getline( ifs , tmp ) ){
    7. if(rawData.size() < MAX_LINES){ // Max_SIZE is a constant I define elsewhere in the program.
    8. rawData.push_back( QString::fromStdString( tmp ) );//Enter data into vector.
    9. }
    10. }
    11. return EXIT_SUCCESS;
    12. }
    13. else return EXIT_FAILURE;
    14. }
    To copy to clipboard, switch view to plain text mode 

    Again, I have outputted the vector and everything is correct. It is quite confusing. :/

Similar Threads

  1. qt 4.8.1 and qdir entryInfoList problem
    By moti.lahiani in forum Qt Programming
    Replies: 3
    Last Post: 18th April 2012, 11:56
  2. Problem with QDir::cdUp()
    By nuntawat in forum Qt Programming
    Replies: 1
    Last Post: 29th March 2010, 01:15
  3. problem with mkdir() in QFtp
    By fatima in forum Qt Programming
    Replies: 3
    Last Post: 20th July 2009, 23:35
  4. Problem with vector
    By cwnelatury in forum Qt Programming
    Replies: 2
    Last Post: 28th May 2009, 03:10
  5. QDir Path problem
    By ToddAtWSU in forum Qt Programming
    Replies: 3
    Last Post: 21st August 2008, 12:15

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
  •  
Qt is a trademark of The Qt Company.