将主要参数传递给gui库的init函数 [英] Passing main arguments to init functions of gui libraries
问题描述
当涉及库(如Qt和GTK)中的库初始化时
必须将主参数传递到初始化库的函数中。为什么?什么是库与他们做?
Qt和GTK +的设计是为了方便回应某些命令行标志。 (两者都响应各种环境变量。)您不一定要将argv和argc发送到相应的init函数,但它并不会受到伤害,特别是如果您打算利用这些功能。
以下是GTK + 有说:
虽然您预计会通过argc ,从
main()到这个函数的argv参数,如果argv不是
可用或不需要命令行处理,可以传递NULL。
argc和argv会相应地进行调整,以便您自己的代码永远不会看到
这些标准参数。
完整列表GTK +接受的命令行选项在这里。
Qt的QApp同样接受命令行参数并删除它接受的参数。这与 QApplication构造函数文档中接受的参数一起记录。When it comes to a library initialization in libraries such as Qt and GTK+ You have to pass the main arguments into the function that initializes the library. Why? What is the library doing with them?
解决方案Both Qt and GTK+ are designed to respond to certain command line flags for convenience. (Both respond to various environment variables as well.) You don't necessarily have to send argv and argc to the corresponding init functions, but it doesn't hurt, particularly if you intend to take advantage of the features.
Here's what the GTK+ documentation for gtk_init() has to say:
Although you are expected to pass the argc , argv parameters from main() to this function, it is possible to pass NULL if argv is not available or commandline handling is not required.
argc and argv are adjusted accordingly so your own code will never see those standard arguments.
A full list of the command line options that GTK+ accepts is here.
Qt's QApplication similarly accepts command line arguments and removes the ones that it accepts. This is documented along with the accepted arguments in the QApplication constructor documentation.
这篇关于将主要参数传递给gui库的init函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!