Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt Application with CLI Commands
Forum Updated to NodeBB v4.3 + New Features

Qt Application with CLI Commands

Scheduled Pinned Locked Moved General and Desktop
18 Posts 3 Posters 7.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    croussou
    wrote on last edited by
    #1

    Hi there,

    I am interested in making an application which somehow provides similar functionalities with Windows command prompt. To simplify things, I want to be able to create a new folder or rename an existing folder in my hard disk using this application. Is this possible to be done? Can I use the existing commands of the Windows command prompt but through my application?

    Thank you in advance.

    Regards,

    croussou

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      You may use "QProcess":http://developer.qt.nokia.com/doc/qt-4.8/qprocess.html in general.
      Concerning of file functionalities they are available through "QDir::mkdir":http://developer.qt.nokia.com/doc/qt-4.8/qdir.html#mkdir -or for files through QFile-.

      [Edit] QDir provides probably all functionality you need.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • C Offline
        C Offline
        croussou
        wrote on last edited by
        #3

        Thanks for you reply.

        Indeed those classes look promising to what I am looking for.

        Any ideas about adding a file in a .zip, .rar file from a Qt application?

        Couldn't get much information online concerning that.

        Cheers.

        Regards,

        croussou

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mlong
          wrote on last edited by
          #4

          If it's a file that already exists on disk, you could use a QProcess to make a call to a standalone .zip or .rar application.

          Edit: (As koahnig already mentioned above.)

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          1 Reply Last reply
          0
          • C Offline
            C Offline
            croussou
            wrote on last edited by
            #5

            Will it be possible to open that .zip file later on with a zip utility software like winrar, 7z or winzip?

            Because I have done something similar but the file cannot be opened...

            Regards,

            croussou

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mlong
              wrote on last edited by
              #6

              If you're using QProcess to access an external zip utility from inside of your program, then it should produce the same results as if you were calling it from the command line; the external application has no idea that it's being called from inside of your program.

              Software Engineer
              My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

              1 Reply Last reply
              0
              • C Offline
                C Offline
                croussou
                wrote on last edited by
                #7

                Aha...is there an example you can give for using the QProcess for zipping a .txt file using for example 7z? Something that I could apply to my own solution maybe?

                Seems there is not a huge amount of information regarding Qt, that's quite sad because I am just starting...

                Regards,

                croussou

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mlong
                  wrote on last edited by
                  #8

                  There's a ton of information regarding Qt. It's one of the most well documented toolkits around. I'm not sure where you've been looking. Have you tried the "QProcess":http://developer.qt.nokia.com/doc/qt-4.8/qprocess.html docs?

                  Here's a brief example lifted directly from those docs. I don't know the command line parameters for 7z, but it should work the same as this example below. Just substitute the 7z executable for "analogclock" and use the proper command line parameters that are expected. Not a difficult exercise.

                  @
                  QObject *parent;
                  ...
                  QString program = "./path/to/Qt/examples/widgets/analogclock";
                  QStringList arguments;
                  arguments << "-style" << "motif";

                   QProcess *myProcess = new QProcess(parent);
                   myProcess->start(program, arguments);
                  

                  @

                  Software Engineer
                  My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    croussou
                    wrote on last edited by
                    #9

                    Quite simple indeed. Can I hide the command prompt or software interface while this is taking place? I do not want the user to see that a 3rd party application is behind this...

                    Regards,

                    croussou

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      mlong
                      wrote on last edited by
                      #10

                      I don't believe that a command prompt or anything should appear. It's all handled in the background. It doesn't actually open a command prompt window and type in the commands.

                      Software Engineer
                      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                      1 Reply Last reply
                      0
                      • C Offline
                        C Offline
                        croussou
                        wrote on last edited by
                        #11

                        Those arguments seem a little tricky...How's the order they should be written? For example the command line command for 7z is "7za a -t7z files.7z text1.txt" to create files.7z with text1.txt inside.

                        @QApplication a(argc, argv);

                        QObject *parent;
                        QString program = "C:\Software\7za920\7za.exe";
                        QStringList arguments;
                        arguments << "7za a -t7z files.7z text1.txt";
                        QProcess *myProcess = new QProcess(parent);
                        myProcess->start(program, arguments);
                        
                        zipfile w;
                        w.show();
                        
                        return a.exec&#40;&#41;;@
                        

                        Regards,

                        croussou

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          mlong
                          wrote on last edited by
                          #12

                          @
                          QString program = "C:\Software\7za920\7za.exe"; // This is the app
                          QStringList arguments;
                          arguments << "a" << "-t7z" << "files.7z" << "text1.txt"; // Don't need "7za" here, it's already covered up there.
                          @

                          Software Engineer
                          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                          1 Reply Last reply
                          0
                          • C Offline
                            C Offline
                            croussou
                            wrote on last edited by
                            #13

                            Hmm...done but it doesn't work...but where do we specify where the .txt file is located? How does the program know where to get it from?

                            Regards,

                            croussou

                            1 Reply Last reply
                            0
                            • M Offline
                              M Offline
                              mlong
                              wrote on last edited by
                              #14

                              Well, I would assume that you would know where the file is that you're wanting to work with. Shouldn't you probably just use the full path to it? "/path/to/text1.txt"

                              Software Engineer
                              My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                              1 Reply Last reply
                              0
                              • C Offline
                                C Offline
                                croussou
                                wrote on last edited by
                                #15

                                Still...

                                @QObject *parent;
                                QString program = "/Software/7za920/7za.exe";
                                QStringList arguments;
                                arguments << "a" << "-t7z" << "/Users/croussou_dm4/Desktop/files.7z" << "/Users/croussou_dm4/Desktop/text1.txt";
                                QProcess *myProcess = new QProcess(parent);
                                myProcess->start(program, arguments);@

                                By the way, thanks for your support...

                                Regards,

                                croussou

                                1 Reply Last reply
                                0
                                • M Offline
                                  M Offline
                                  mlong
                                  wrote on last edited by
                                  #16

                                  I'd suggest reading through the docs for QProcess. There are various ways to find the return code of the finished process (was it ok?) or to read from stderr (were there any error messages), and that sort of thing.

                                  In the long run, it will be much more beneficial than me or anyone else trying to guess what the problems may be.

                                  By the way, you're welcome!

                                  Software Engineer
                                  My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                                  1 Reply Last reply
                                  0
                                  • C Offline
                                    C Offline
                                    croussou
                                    wrote on last edited by
                                    #17

                                    Again thank you very much.

                                    I will look into that.

                                    Regards,

                                    croussou

                                    1 Reply Last reply
                                    0
                                    • M Offline
                                      M Offline
                                      mlong
                                      wrote on last edited by
                                      #18

                                      Be sure and let us know what you find out!

                                      Software Engineer
                                      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                                      1 Reply Last reply
                                      0

                                      • Login

                                      • Login or register to search.
                                      • First post
                                        Last post
                                      0
                                      • Categories
                                      • Recent
                                      • Tags
                                      • Popular
                                      • Users
                                      • Groups
                                      • Search
                                      • Get Qt Extensions
                                      • Unsolved