You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

tillias

Trainee

  • "tillias" started this thread

Posts: 60

Location: Russian Federation, Voronezh

  • Send private message

1

Thursday, April 26th 2007, 5:59am

QDirModel and filenames with spaces

Hi!

My QProcess doesn't run command if it contains spaces in filenames.
E.g. if I run such a line from command line ( bash or sh ):
$mplayer dvd://1 -dvd-device /mnt/work/video/torrents/HQ/Film\ 1\ 2\ 3
it works.
But if I run exactly the same line from QProcess -- it doesn't work:

Source code

1
2
QProcess my_process;
my_process.start(QString(mlayer dvd://1 -dvd-device /mnt/work/video/torrents/HQ/Film\ 1\ 2\ 3));


Here we go:

1. extract filename from QTreeView ( QDirModel ):

Source code

1
2
QModelIndex cur_index = directory_browser->currentIndex();
QString dvd_dir_name = directories->filePath( cur_index )


dvd_dir_name == "dir 1 2 3" ( for example )

2. replace all spaces with '\ ' construction:

Source code

1
dvd_dir_name.replace( QRegExp( " " ), "\\ " );


dvd_dir_name == "dir\ 1\ 2\ 3"

3. Prepare command line:

Source code

1
2
QString command_line = "some_process";
     command_line += dvd_dir_name;


command_line == "some_process dir\ 1\ 2\ 3"

4. Finally run process with command_line:

Source code

1
2
QProcess mplayer_process;
mplayer_process.start( command_line);


On my Linux machine QProcess runs such a command:

Source code

1
$mplayer dvd://1 -dvd-device /mnt/work/video/torrents/HQ/Film\ 1\ 2\ 3


The problem is if I run mplayer from QProcess -- it fails, but if I run exactly the same command from bash or sh it works fine...
What may it be with QProcess and spaces in dir filename?

P.S. here is log for mplayer:

Source code

1
2
3
4
5
6
7
8
9
10
Playing dvd://1.


Playing 1\.


Playing 2\.


Playing 3.
God bless you!

Junior

Professional

  • "Junior" is male

Posts: 1,613

Location: San Antonio, TX USA

Occupation: Senior Secure Systems Engineer

  • Send private message

2

Thursday, April 26th 2007, 1:38pm

RE: QDirModel and filenames with spaces

tillias,

Use the QProcess start( program, args ) instead of the start(program).

Something like:


QString program = "mplayer";
QStringList args;
args << "dvd://1";
args << "-dev-device";
args << etc......

my_process.start( program, args );

....


Hope this helps.

Junior