Results 1 to 4 of 4

Thread: Unable to start linux process by Qt

  1. #1
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Exclamation Unable to start linux process by Qt

    Hello everybody,

    I have got stucked somewhere in my code.
    I want to copy all the content from one directory to another, means copy data from source to destination.
    I have written the below code, But its not working
    And i dont know why

    Qt Code:
    1. QScopedPointer<QProcess> my_process(new QProcess());
    2.  
    3. QString source = parent_path;
    4. source.append(QDir::separator());
    5. source.append("*");
    6.  
    7. QString destination = map_path;
    8. destination.append(QDir::separator());
    9.  
    10. qDebug() << "Source : " << source;
    11. qDebug() << "Destination : " << destination;
    12.  
    13. QStringList arguments;
    14. arguments << "-rf"
    15. << source
    16. << destination;
    17. my_process->start("cp", arguments);
    18.  
    19. qDebug() << "Copied : " << my_process->waitForFinished();
    20. qDebug() << my_process->errorString();
    To copy to clipboard, switch view to plain text mode 

    Please tell me what is the problem in my code.,??????
    Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Unable to start linux process by Qt

    Your problem is most likely that your wildcards are not expanded. This is usually done by the shell, but you are not invoking the cp command through a shell but directly.

    As far as I can see you have a couple of options:
    1) create a list of file using QDir and then pass them to the cp command as input followed by the target dir
    2) create a helper script that will internall pass its parameters to cp, expanding the in the process
    3) call a shell and use its commandline arguments to run cp as a child command
    4) copy in Qt by listing all files and calling QFile::copy() on each, probably doing all that in a thread in order not to block the main thread
    5) create a small helper program in Qt that uses (4) in its main thread and is called by the main program through QProcess

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    karankumar1609 (19th December 2013)

  4. #3
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,478
    Thanked 274 Times in 269 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Unable to start linux process by Qt

    "parent_path" is absolute or relative ? If relative what is current dir in application ?

  5. The following user says thank you to Lesiok for this useful post:

    karankumar1609 (19th December 2013)

  6. #4
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Unable to start linux process by Qt

    I have chnaged my code below

    Qt Code:
    1. QScopedPointer<QProcess> my_process(new QProcess());
    2.  
    3. QString source = parent_path;
    4. source.append(QDir::separator());
    5. // source.append("*");
    6.  
    7. QString destination = map_path;
    8. destination.append(QDir::separator());
    9.  
    10. qDebug() << "Source : " << source;
    11. qDebug() << "Destination : " << destination;
    12.  
    13. QStringList arguments;
    14. arguments << "-rf"
    15. << source
    16. << destination;
    17. my_process->start("cp", arguments);
    18.  
    19. qDebug() << "Copied : " << my_process->waitForFinished();
    20. qDebug() << my_process->errorString();
    To copy to clipboard, switch view to plain text mode 

    Now it makes the data Directory in the destination directory.

    Source = "/home/DATA/"
    Destination = "/home/DATA_MAP/"

    now it creates the DATA folder in my DATA_MAP folder.
    I just want my data content in my DATA_MAP directory


    Added after 12 minutes:


    "parent_path" is the absolute path.

    //////////////////////////////////
    Following code wors for me

    Qt Code:
    1. {
    2. QDir dir(parent_path);
    3.  
    4. QStringList dirs = dir.entryList(QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot);
    5.  
    6. foreach(QString directory, dirs) {
    7. QString source = parent_path;
    8. source.append(QDir::separator());
    9. source.append(directory);
    10. qDebug() << "Source : " << source;
    11.  
    12. QString destination = map_path;
    13. destination.append(QDir::separator());
    14.  
    15. QScopedPointer<QProcess> my_process(new QProcess());
    16.  
    17. connect(this, SIGNAL(stopProcessing()), my_process.data(), SLOT(kill()), Qt::DirectConnection);
    18. QStringList arguments;
    19. arguments << "-rf"
    20. << source
    21. << destination;
    22.  
    23. my_process->start("cp", arguments);
    24.  
    25. qDebug() << "Copied : " << my_process->waitForFinished(-1);
    26. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by karankumar1609; 19th December 2013 at 11:17.
    Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.

Similar Threads

  1. QProcess : unable to start sis file
    By javed_alam786 in forum Qt for Embedded and Mobile
    Replies: 6
    Last Post: 26th August 2011, 13:42
  2. Replies: 9
    Last Post: 15th April 2011, 07:51
  3. Replies: 2
    Last Post: 14th March 2011, 20:55
  4. Replies: 5
    Last Post: 13th March 2010, 14:03
  5. The Gdb process failed to start.
    By been_1990 in forum Qt Tools
    Replies: 3
    Last Post: 29th April 2009, 17:29

Tags for this Thread

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.