PDA

View Full Version : Using vector's with QProcess



SirJonas
23rd October 2016, 18:48
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:


//store the paths you iterate
std::vector<QString> paths;
paths.emplace_back("first path");
paths.emplace_back("second path");
if(input_path == "cd"){
QDir new_path(paths.back());
new_path.cd();
paths.emplace_back(new_path.absolutePath());
}

//back to previous path, stl split back and pop_back to two actions for the sake of exception safe
auto const path = paths.back();
paths.pop_back();
It's for learning more about vector's

anda_skoa
23rd October 2016, 20:11
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.



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.



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,
_

jefftee
23rd October 2016, 20:30
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.

SirJonas
23rd October 2016, 20:57
Sorry yeah i was thinking that with vector i can use in this example but i can do too with this:

QProcess consola;
if(comando.left(2)=="cd"){
QDir::setCurrent(comando.mid(3));
consola.start("cmd.exe /C " + comando);
}
if(comando==".."){
QDir::setCurrent("..");
}
consola.start("cmd.exe /C " + comando);
consola.waitForFinished();
consola.waitForReadyRead();

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.

jefftee
23rd October 2016, 21:24
You still don't have a clue how to use QProcess nor have you understood any of the previous advice you've been given.

anda_skoa
23rd October 2016, 21:28
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.



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.



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,
_