如何在后台启动应用程序,即不显示 GUI?
我正在使用 Qt 进行屏幕截图(丝网打印)。
QPixmap::grabWindow(QApplication::desktop()->winId());
我希望应用程序在后台启动,即我希望它在启动时隐藏(甚至在控制台模式下运行)。
如何在 Qt 中做到这一点?
I'm using Qt for taking screenshots (screen printing).
QPixmap::grabWindow(QApplication::desktop()->winId());
I'd like the application to start in background, i.e. I want it to be hidden when it starts (or even run in console mode).
How can I do that in Qt?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
据我了解,您需要一个在执行时不显示小部件(UI)并在后台运行的应用程序。
实现此目的的一种方法是启动应用程序并在系统托盘中显示图标,而不是在屏幕上显示对话框/窗口。
您可以这样编写代码:
您还需要设置一些其他内容。您可以参考系统托盘图标示例 为此。
2022 年更新:
如果您正在寻找使用全局快捷方式调用应用程序的方法,您可能需要查看 Qxt,因为 libqxt 不再维护,并且可能无法与较新版本的 Qt 一起使用。
As I understand, you need an app that, when executed, doesn't show a widget (UI) and runs in the background.
One way to achieve this is to launch the app and show an icon in System tray instead of showing a dialog/window on the screen.
You can code this something like this:
There are a few other things you'd need to set. You can refer to the System Tray Icon Example for that.
Update 2022:
If you are looking for a way to invoke the app using a global shortcut you might wanna look into options other than Qxt, as libqxt is no longer maintained and might not work with newer versions of Qt.
您可以从 Qt 控制台应用程序开始。
请记住在标头中包含
。打开您的 .PRO 文件,删除带有
-= gui
的行You can start with Qt Console Application.
Remember to include
<GtGui>
in your headers.Open your .PRO file, remove the line with
-= gui
我建议您使用 QCoreApplication 而不是 QApplication:
顺便说一句,您可以在 QtCreator 中选择 Console App,但我总是使用 Empty Project。
I recommend you to use QCoreApplication instead of QApplication:
By the way, you can select Console App in QtCreator, but I always use Empty Project.