Results 1 to 3 of 3

Thread: QProcess doesn't do the same as the terminal would

  1. #1
    Join Date
    Jan 2011
    Posts
    9
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question QProcess doesn't do the same as the terminal would

    Hi,

    I took the command to create a simple archive using the terminal and put every argument in a QStringlist, but the result is that the program creates an archive called mx9.7z in the folder where the program is located.
    Why doesn't this example program do the same thing as the same command entered in the terminal?
    (7z a -t7z mx9 /home/user/Desktop/Desktop.7z /home/user/Desktop/file1.pdf /home/user/Desktop/file2.doc)

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include <QPushButton>
    3. #include "program.h"
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication a(argc, argv);
    8. QPushButton *okButton = new QPushButton("OK");
    9. Program *mystarter = new Program();
    10. a.connect(okButton, SIGNAL(clicked()), mystarter, SLOT(startprocess()));
    11.  
    12. okButton->setMinimumWidth(150);
    13. okButton->show();
    14. return a.exec();
    15. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #ifndef PROGRAM_H
    2. #define PROGRAM_H
    3. #include <QObject>
    4. #include <QProcess>
    5.  
    6. class Program : public QObject
    7. {
    8. Q_OBJECT
    9. public:
    10. QProcess myprocess;
    11. explicit Program(QObject *parent = 0);
    12.  
    13. public slots:
    14. void startprocess();
    15. };
    16.  
    17. #endif
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #include "program.h"
    2. #include <QString>
    3. #include <QStringList>
    4.  
    5. Program::Program(QObject *parent) : QObject(parent)
    6. {}
    7.  
    8. void Program::startprocess()
    9. {
    10. list << "a" << "-t7z" << "mx9" << "/home/user/Desktop/Desktop.7z" << "/home/user/Desktop/file1.pdf" << "/home/user/Desktop/file2.doc";
    11. myprocess.start("7z", list);
    12. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess doesn't do the same as the terminal would

    Hi,

    the problenm is the 7z command not QProcess

    try with
    Qt Code:
    1. list << "a" << "-t7z" << "-mx9" << "/home/user/Desktop/Desktop.7z" << "/home/user/Desktop/file1.pdf" << "/home/user/Desktop/file2.doc";
    To copy to clipboard, switch view to plain text mode 

    note "-mx9" instead of "mx9"
    A camel can go 14 days without drink,
    I can't!!!

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

    mr_kazoodle (3rd February 2011)

  4. #3
    Join Date
    Jan 2011
    Posts
    9
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QProcess doesn't do the same as the terminal would

    I'm sorry, that was a mistake in my example, but however the example is now working, hm..... I must have made some other mistake somewhere in my real program...
    Thanks anyway


    Added after 25 minutes:


    The program is now working as it should have been.
    I have made the QProcess object a global variable (just like in the example) instead of creating it in the function which starts it.
    And I found that I didn't need to use apostrophe signs around the filenames. I thought I needed to do that because if you don't do that in the terminal you get errors if there are spaces in the filenames or names of the directories. (I think that was also a reason why it didn't work)
    Wow, I can't believed I finally fixed it. I've been searching for this for days.
    Last edited by mr_kazoodle; 3rd February 2011 at 15:53.

Similar Threads

  1. Opening A Terminal using QProcess
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 1
    Last Post: 3rd February 2011, 14:51
  2. terminal widget
    By kernel_panic in forum Qt Programming
    Replies: 11
    Last Post: 21st November 2009, 14:08
  3. help about terminal window
    By andyyeng in forum Qt Programming
    Replies: 0
    Last Post: 29th October 2008, 15:22
  4. Looking for widget to run terminal app
    By marcell in forum Qt Programming
    Replies: 0
    Last Post: 16th May 2008, 16:24
  5. QProcess doesn't terminate
    By Bagstone in forum Qt Programming
    Replies: 4
    Last Post: 8th February 2008, 00:43

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.