QT New Process

Source: Internet
Author: User
Tags printf win32
Qt qprocess

As a framework for almost language-level changes to C + +, the package is similar to cocoa, and, in fact, it feels like Qt has changed the language characteristics of C + + from cocoa to objective C, but the difference is that QT does not dominate the C + + world.
Test1:

#include <QtCore/QCoreApplication>
#include <QtCore/QProcess>
#include <QtCore/QStringList>

int main (int argc, char *argv[])
{
QString program = "Cat";
Qstringlist arguments;
Arguments << "A" << "B";

Qprocess *myprocess =NewQprocess ();
Myprocess->start (program, arguments);
Myprocess->waitforfinished ();
Qbytearray output = Myprocess->readallstandardoutput ();
printf ("%s", (const char*) output);

return0;
}

Qprocess is the process class for QT encapsulation, which needs to be specifically explained by the use of QT4 and Qt3 is different. And, there is a problem because QT is now almost pure GUI-oriented interface library, so qprocess default is the command line does not output, here turn a bend, read out the output, and then output with printf.

Test2:

#include <QtCore/QCoreApplication>
#include <QtCore/QProcess>
#include <QtCore/QStringList>

int main (int argc, char *argv[])
{
QString program = "Cat";
Qstringlist arguments;
Arguments << "A" << "B";

Qprocess *myprocess =NewQprocess ();
Myprocess->setstandardoutputfile ("C");
Myprocess->start (program, arguments);
Myprocess->waitforfinished ();

return0;
}
But looking at the example, what it feels like. Personal feeling Qt deserves to be a special API, relying on the API to eat and rely on the sale of hardware for the company is not the same, API design is just right, concise introduction, and, most importantly, enough.

TEST3:


#include <QtCore/QCoreApplication>
#include <QtCore/QProcess>
#include <QtCore/QStringList>

int main (int argc, char *argv[])
{
QString program = "/bin/cat";
Qstringlist arguments;
Arguments << "A" << "B";

Qprocess *myprocess =NewQprocess ();
Qprocess *outprocess =NewQprocess ();
Myprocess->setstandardoutputprocess (outprocess);

Myprocess->start (program, arguments);
Outprocess->start (program);
Myprocess->waitforfinished ();
Outprocess->waitforfinished ();

Qbytearray output = Outprocess->readallstandardoutput ();
printf ("%s", (const char*) output);
return0;
}

In general, QT does not design pipe corresponding classes, but, for a function can solve the task, it is obvious that the use is more simple, like cocoa, such a simple concept of the corresponding encapsulation, in fact, there is excessive design suspicion .... In fact, Nspipe is also 2, 3 functions, and, as shown in this example, in fact, in addition to a useful, nspipe more than a few of the many are because of the nspipe only appear function .... In sorrow ....

General Table

Usage/code amount
Test1
Test2
Test3
SHELL
Single-line 5 characters
line 7 characters
line 9 characters
C runtime  Library ' s system
5 lines
5 lines
5 lines
Python ' s os.system
2 lines
2 lines
2 lines
Win32 API winexec/shellexecute
6 lines
6 lines
type restrictions
Win32 API CreateProcess
16 lines
16 lines
type restrictions
Objective C with Cocoa
15 lines
23 lines
23 lines
Qt qprocess
16 lines
15 lines
20 lines

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.