QT4:如何重新启动应用程序?重置设置?
1.) 我想重新启动我的 QT4 应用程序。只是同一应用程序的正常关闭和启动。
2.) 为什么?好吧,我需要一个选项来“重置”一切。重新启动应用程序似乎是最简单的方法。问题是,有很多课程和一切。我没有时间将它们的每个设置恢复为标准,每个文本框,小部件都需要清除...我知道应用程序重新启动不是最好的方法,您认为还有其他方法吗?
谢谢
1.) I would like to restart my QT4 application. Just a normal shutdown and start of the same application.
2.) Why? Well i need an Option to "reset" everything. To restart the application seems to be the easiest way to do this. The problem is, that there are a LOT of classes and everything. I dont have the time to put every setting of them back to standard, every textBox, Widget to clear... I Know application restart is not the best way, what do you think is there another way?
Thank You
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
要重新启动应用程序,您可以在退出进程后使用
startDetached
:For restarting an application you can use
startDetached
after quiting the process:1) 您可以运行脚本,安排操作系统稍后启动您的应用程序。
2)编写一个单独的类,其中包含所有应用程序设置。需要时重置。
1) You can run a Script, Schedule the OS to start your app later.
2) Write a separate class which contains all your application Settings. Reset whenever required.
有趣的请求。只需保留“重新启动”的退出代码并执行类似(未经测试)的操作:
然后您可以在任何地方调用 QApplication::exit(EXIT_RESTART) ,您应该可以开始了。或者使用包装脚本来执行相同的操作。 (如果您的应用程序需要任何命令行参数,请确保在这两种情况下都能令人满意地处理命令行参数。)
更简洁的方法是将所有需要重置的内容连接到同一信号。
Funny request. Just reserve an exit code for "restart" and do something like (untested):
Then you can just call QApplication::exit(EXIT_RESTART) anywhere and you should be good to go. Or use a wrapper script to do the same. (Make sure in both cases that you handle command line arguments satisfactorily if you app takes any.)
A cleaner approach would be to connect all the things that need to be reset to the same signal.
您可以删除这些类并在同一 QApplication 下的 main() 中创建新类
you could delete the classes and create new ones in main() under the same QApplication
在这种情况下,明智的做法是将创建/初始化小部件等的所有内容放在单个函数中(当然,它可以调用子函数)。当您需要重置所有内容时,只需调用它即可。根据具体的实现,您可能需要首先删除/取消初始化这些内容。
The sane thing to do in such a case is to put all the stuff that creates/initializes widgets, etc., in a single function (of course, it can call sub-functions). When you need to reset everything, simply call it. Depending on the exact implementation, you may need to delete/un-initialize the stuff first.
该方法适用于 PyQt。我编写它是为了擦除所有设置并使用干净的设置重新启动应用程序。
application_main
是主方法,clearSettings
是清除设置的槽。This method works on PyQt. I wrote it for erasing all settings and to restart the application with clean settings.
application_main
is the main method, andclearSettings
is the slot that clears the settings.