Results 1 to 6 of 6

Thread: Using vector's with QProcess

  1. #1
    Join Date
    Oct 2016
    Posts
    61
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Using vector's with QProcess

    Hi i am using QProces but everyone know that the path never is recorded. And like i'm learning about vector's i am trying to do one example with this.

    I was thinking to use this:
    First i put the path so with this new_path.cd(path); i change the path and with the follow code i return back with
    auto const path = paths.back();
    paths.pop_back();

    Or i change the path with cd Path so what do you think good idea?

    Code:

    Qt Code:
    1. //store the paths you iterate
    2. std::vector<QString> paths;
    3. paths.emplace_back("first path");
    4. paths.emplace_back("second path");
    5. if(input_path == "cd"){
    6. QDir new_path(paths.back());
    7. new_path.cd();
    8. paths.emplace_back(new_path.absolutePath());
    9. }
    10.  
    11. //back to previous path, stl split back and pop_back to two actions for the sake of exception safe
    12. auto const path = paths.back();
    13. paths.pop_back();
    To copy to clipboard, switch view to plain text mode 
    It's for learning more about vector's
    Last edited by SirJonas; 23rd October 2016 at 20:06.

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

    Default Re: Using vector's with QProcess

    Quote Originally Posted by SirJonas View Post
    Hi i am using QProces but everyone know that the path never is recorded.
    What?

    This doesn't even make sense for those of us who have figured out that you are posting with two accounts now.

    Your other account's problem was not with QProcess or paths, but with launching different shell operations in different processes and wondering why one did not affect the other, totally unrelated, one.

    Quote Originally Posted by SirJonas View Post
    And like i'm learning about vector's i am trying to do one example with this.
    I doubt that, this thread has nothing to do with vectors other than you using one for storing strings.

    Quote Originally Posted by SirJonas View Post
    It's for learning more about vector's
    If this is really about learning about vectors, why don't you ask a question about what you need to know about them?

    Cheers,
    _

  3. #3
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Using vector's with QProcess

    Not sure I understand your comment "path is never recorded", but if you want to set the current working directory for a QProcess, then use QProcess::setWorkingDirectory.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  4. #4
    Join Date
    Oct 2016
    Posts
    61
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Using vector's with QProcess

    Sorry yeah i was thinking that with vector i can use in this example but i can do too with this:
    Qt Code:
    1. QProcess consola;
    2. if(comando.left(2)=="cd"){
    3. QDir::setCurrent(comando.mid(3));
    4. consola.start("cmd.exe /C " + comando);
    5. }
    6. if(comando==".."){
    7. QDir::setCurrent("..");
    8. }
    9. consola.start("cmd.exe /C " + comando);
    10. consola.waitForFinished();
    11. consola.waitForReadyRead();
    To copy to clipboard, switch view to plain text mode 
    The only thing sometimes when i change the directory show me this:
    QProcess::start: Process is already running
    QProcess::start: Process is already running

    when you say Your other account's problem yeah sorry i forgot how to access in them. i lost the pass to re-enter again.

    Anyways i want to learn about vector's like push_back or store string but at the moment i'm not doing one example only for this and i was thinking would be nice to store the path one big mistake.

    Sorry again for all and for help me a lot.

  5. #5
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Using vector's with QProcess

    You still don't have a clue how to use QProcess nor have you understood any of the previous advice you've been given.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Using vector's with QProcess

    Quote Originally Posted by SirJonas View Post
    The only thing sometimes when i change the directory show me this:
    QProcess::start: Process is already running
    QProcess::start: Process is already running
    Have you actually looked at your own code?
    If "comando" starts with "cd" you are calling start() twice.

    And again, probably for the fifth, or sixth time now, you are doing it all wrong, each "cmd" call is independent of each other.

    Quote Originally Posted by SirJonas View Post
    when you say Your other account's problem yeah sorry i forgot how to access in them. i lost the pass to re-enter again.
    Aside from being a lie, as both account have posted in parallel over a couple of days, maybe, instead of wasting everyone's time, try to at least read some of the responses you get.

    Like the one on the previous thread to that problem where someone suggested you just execute a script that does all these steps instead of your futile battle to hack around an unsolvable lack of understanding of how "cmd" works.

    Quote Originally Posted by SirJonas View Post
    Anyways i want to learn about vector's like push_back or store string but at the moment i'm not doing one example only for this and i was thinking would be nice to store the path one big mistake.
    Your vector operations look fine.
    Which of them do you have a problem with?

    Cheers,
    _
    Last edited by anda_skoa; 23rd October 2016 at 22:34.

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

    jefftee (23rd October 2016)

Similar Threads

  1. Replies: 1
    Last Post: 3rd June 2013, 14:11
  2. Copying vector of pointers to another vector
    By Momergil in forum Newbie
    Replies: 12
    Last Post: 24th September 2011, 23:09
  3. vector of vector and computes
    By mickey in forum General Programming
    Replies: 1
    Last Post: 15th May 2008, 13:47
  4. insert in a vector of vector
    By mickey in forum General Programming
    Replies: 3
    Last Post: 6th March 2007, 09:45
  5. vector of vector size
    By mickey in forum General Programming
    Replies: 5
    Last Post: 13th February 2007, 16:59

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.