Hi. I seem to have a problem where I dont understand the cause. I have read as much as I can trying to figure out what is my problem but alas, here I am humbly seeking assistance.

I am working on a small and simple gui to generate plaintext config files that will be read by another program. I have output working fine but the problem arises when I try to input a QString that has spaces (a windows pathname to My Documents), my input is truncated at the first space in the string.

My settings file looks like this (or very similar):

server=example.com
protocol=sftp
port=23
username=mark
password=
backupdir=c:\My Documents\backup
firefox=1
path=c:\Program Files\Firefox\firefox.exe
I use QString::section() to get rid of the variable label which seems to work. Its just that pesky white space.

Qt Code:
  1. //###########################
  2. void MainWindow::load()
  3. //###########################
  4. {
  5. QString str, chopped;
  6. int num;
  7.  
  8. QFile file("settings.cfg");
  9.  
  10. if (!file.open(QIODevice::ReadOnly))
  11. {
  12. cerr << "Cannot read file for loading: " << qPrintable(file.errorString()) << endl;
  13. loadDefaults();
  14. return;
  15. }
  16.  
  17. QTextStream input(&file);
  18.  
  19. // Server
  20. input >> str;
  21. chopped = str.section('=', 1);
  22. server_lineEdit->setText(chopped);
  23.  
  24. // Protocol
  25. input >> str;
  26. chopped = str.section('=', 1);
  27. if ( chopped == "sftp" )
  28. sftp_radioButton->setChecked(true);
  29. else
  30. ftp_radioButton->setChecked(true);
  31.  
  32. ...
  33.  
  34. // Backup Directory
  35. //input >> str;
  36. QString line = input.readLine();
  37. chopped = line.section('=', 1);
  38. backup_dir_lineEdit->setText(line);
  39.  
  40. // Firefox
  41. input >> str;
  42. chopped = str.section('=', 1);
  43.  
  44. if (chopped == QString::number(1))
  45. firefoxBox->setChecked(false);
  46. else
  47. firefoxBox->setChecked(true);
  48. // Path
  49. input >> str;
  50. //str = input.readLine();
  51.  
  52. chopped = str.section('=', 1);
  53. firefox_path_lineEdit->setText(chopped);
  54.  
  55. }
To copy to clipboard, switch view to plain text mode 

As you can see I have tried readLine() and a normal stream operators. The code in there now, the readLine() does not return anything to the lineEdit and if I switch it back to str << ... I get truncated path names. Please can someone point me in the direction of what I need. Thanks!