• 13901阅读
  • 12回复

【提问】请问QT怎么和外面的程序相连? [复制链接]

上一主题 下一主题
离线guhuo
 
只看楼主 倒序阅读 楼主  发表于: 2005-09-14
比如点一个按钮产生signal, 然后执行一个不是在qt里写的应用程序。。谢谢。
嵌入式linux嘿嘿
qq:
15416920
离线XChinux

只看该作者 1楼 发表于: 2005-09-14
这个可以直接使用C库函数来解决,比如
system(), exec()等等这些函数。
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线yfy002

只看该作者 2楼 发表于: 2005-09-14
qprocess
我渴望平静,风却给了我涟漪
我的blog:
http://sungaoyong.cublog.cn
离线XChinux

只看该作者 3楼 发表于: 2005-09-14
或者使用QProcess
QProcess::execute(const QString & program, const QStringList & arguments);
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线guhuo
只看该作者 4楼 发表于: 2005-09-14
...我怎么没找到这个类?         谢谢


还有要是 直接使用C库函数 那在程序里 includeC库函数的目录 吧   谢谢
嵌入式linux嘿嘿
qq:
15416920
离线XChinux

只看该作者 5楼 发表于: 2005-09-14
对的,要include相应的头文件
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线guhuo
只看该作者 6楼 发表于: 2005-09-14
我没找到 QProcess 这个类丫。。。。
嵌入式linux嘿嘿
qq:
15416920
离线XChinux

只看该作者 7楼 发表于: 2005-09-14
没有找到的话那就使用C库函数吧。

#include <stdlib.h>
int system( const char *command );
The system() function runs the given command as a system call. The return value is usually zero if the command executed without errors. If command is NULL, system() will test to see if there is a command interpreter available. Non-zero will be returned if there is a command interpreter available, zero if not.
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线XChinux

只看该作者 8楼 发表于: 2005-09-14
下面的是exec族系的

Header File
process.h
Category
Process Control Routines
Prototype
int execl(char *path, char *arg0 *arg1, ..., *argn, NULL);
int _wexecl(wchar_t *path, wchar_t *arg0 *arg1, ..., *argn, NULL);
int execle(char *path, char *arg0, *arg1, ..., *argn, NULL, char **env);
int _wexecle(wchar_t *path, wchar_t *arg0, *arg1, ..., *argn, NULL, wchar_t **env);
int execlp(char *path, char *arg0,*arg1, ..., *argn, NULL);
int _wexeclp(wchar_t *path, wchar_t *arg0,*arg1, ..., *argn, NULL);
int execlpe(char *path, char *arg0, *arg1, ..., *argn, NULL, char **env);
int _wexeclpe(wchar_t *path, wchar_t *arg0, *arg1, ..., *argn, NULL, wchar_t **env);
int execv(char *path, char *argv[]);
int _wexecv(wchar_t *path, wchar_t *argv[]);
int execve(char *path, char *argv[], char **env);
int _wexecve(wchar_t *path, wchar_t *argv[], wchar_t **env);
int execvp(char *path, char *argv[]);
int _wexecvp(wchar_t *path, wchar_t *argv[]);
int execvpe(char *path, char *argv[], char **env);
int _wexecvpe(wchar_t *path, wchar_t *argv[], wchar_t **env);
Description
Loads and runs other programs.
The functions in the exec... family load and run (execute) other programs, known as child processes. When an exec... call succeeds, the child process overlays the parent process. There must be sufficient memory available for loading and executing the child process.
path is the file name of the called child process. The exec... functions search for path using the standard search algorithm:
If no explicit extension is given, the functions search for the file as given. If the file is not found, they add .EXE and search again. If not found, they add .COM and search again. If found, the command processor, COMSPEC (Windows) or COMMAND.COM (DOS), is used to run the batch file.
    If an explicit extension or a period is given, the functions search for the file exactly as given.
The suffixes l, v, p, and e added to the exec... "family name" specify that the named function operates with certain capabilities.
l     specifies that the argument pointers (arg0, arg1, ..., argn) are passed as separate arguments. Typically, the l suffix is used when you know in advance the number of arguments to be passed.
v     specifies that the argument pointers (argv[0] ..., arg[n]) are passed as an array of pointers. Typically, the v suffix is used when a variable number of arguments is to be passed.
p     specifies that the function searches for the file in those directories specified by the PATH environment variable (without the p suffix, the function searches only the current working directory). If the path parameter does not contain an explicit directory, the function searches first the current directory, then the directories set with the PATH environment variable.
e     specifies that the argument env can be passed to the child process, letting you alter the environment for the child process. Without the e suffix, child processes inherit the environment of the parent process.
Each function in the exec... family must have one of the two argument-specifying suffixes (either l or v). The path search and environment inheritance suffixes (p and e) are optional; for example:
execl is an exec... function that takes separate arguments, searches only the root or current directory for the child, and passes on the parent's environment to the child.
    execvpe is an exec... function that takes an array of argument pointers, incorporates PATH in its search for the child process, and accepts the env argument for altering the child's environment.
The exec... functions must pass at least one argument to the child process (arg0 or argv[0]); this argument is, by convention, a copy of path. (Using a different value for this 0th argument won't produce an error.)
path is available for the child process.
When the l suffix is used, arg0 usually points to path, and arg1, ..., argn point to character strings that form the new list of arguments. A mandatory null following argn marks the end of the list.
When the e suffix is used, you pass a list of new environment settings through the argument env. This environment argument is an array of character pointers. Each element points to a null-terminated character string of the form
  envvar = value
where envvar is the name of an environment variable, and value is the string value to which envvar is set. The last element in
env is null. When env is null, the child inherits the parents' environment settings.
The combined length of arg0 + arg1 + ... + argn (or of argv[0] + argv[1] + ... + argn[n]), including space characters that separate the arguments, must be less than 260 bytes. Null terminators are not counted.
When an exec... function call is made, any open files remain open in the child process.
Return Value
If successful, the exec... functions do not return. On error, the exec... functions return -1, and the global variable errno is set to one of the following values:
EACCES     Permission denied
EMFILE     Too many open files
ENOENT     Path or file name not found
ENOEXEC     Exec format error
ENOMEM     Not enough memory
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线guhuo
只看该作者 9楼 发表于: 2005-09-15
不好意思,本人菜, 再问一下
在qt的程序里#include <stdlib.h>就可以么?


g++ 时, -I 了qt的目录了,   是不是#include <stdlib.h>就不对了?
嵌入式linux嘿嘿
qq:
15416920
离线XChinux

只看该作者 10楼 发表于: 2005-09-15
那是标准C库文件,应该都能行的。
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线zwcxxl

只看该作者 11楼 发表于: 2005-09-15
qt实际上就是C++的图形库,C++的特性和操作大多都可以在qt里使用。
离线tdrhsb
只看该作者 12楼 发表于: 2005-09-17
下面是引用guhuo于2005-09-14 16:22发表的【提问】请问QT怎么和外面的程序相连?:
比如点一个按钮产生signal, 然后执行一个不是在qt里写的应用程序。。谢谢。

你可以通过发QCop消息通知别的进程!
快速回复
限100 字节
 
上一个 下一个