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.
//###########################
void MainWindow::load()
//###########################
{
int num;
QFile file("settings.cfg");
{
cerr << "Cannot read file for loading: " << qPrintable(file.errorString()) << endl;
loadDefaults();
return;
}
// Server
input >> str;
chopped = str.section('=', 1);
server_lineEdit->setText(chopped);
// Protocol
input >> str;
chopped = str.section('=', 1);
if ( chopped == "sftp" )
sftp_radioButton->setChecked(true);
else
ftp_radioButton->setChecked(true);
...
// Backup Directory
//input >> str;
chopped = line.section('=', 1);
backup_dir_lineEdit->setText(line);
// Firefox
input >> str;
chopped = str.section('=', 1);
firefoxBox->setChecked(false);
else
firefoxBox->setChecked(true);
// Path
input >> str;
//str = input.readLine();
chopped = str.section('=', 1);
firefox_path_lineEdit->setText(chopped);
}
//###########################
void MainWindow::load()
//###########################
{
QString str, chopped;
int num;
QFile file("settings.cfg");
if (!file.open(QIODevice::ReadOnly))
{
cerr << "Cannot read file for loading: " << qPrintable(file.errorString()) << endl;
loadDefaults();
return;
}
QTextStream input(&file);
// Server
input >> str;
chopped = str.section('=', 1);
server_lineEdit->setText(chopped);
// Protocol
input >> str;
chopped = str.section('=', 1);
if ( chopped == "sftp" )
sftp_radioButton->setChecked(true);
else
ftp_radioButton->setChecked(true);
...
// Backup Directory
//input >> str;
QString line = input.readLine();
chopped = line.section('=', 1);
backup_dir_lineEdit->setText(line);
// Firefox
input >> str;
chopped = str.section('=', 1);
if (chopped == QString::number(1))
firefoxBox->setChecked(false);
else
firefoxBox->setChecked(true);
// Path
input >> str;
//str = input.readLine();
chopped = str.section('=', 1);
firefox_path_lineEdit->setText(chopped);
}
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!
Bookmarks