如何在非GUI应用程序中使用QWebPage [英] how to use QWebPage in a non-GUI application

查看:157
本文介绍了如何在非GUI应用程序中使用QWebPage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在非GUI Qt应用程序中使用QWebPage.通过这种方式,我的意思是我根本不想与窗口服务器进行通信.不过,使用QtGui并不是问题.

I want to use QWebPage in a non-GUI Qt application. By that, I mean that I don't want to communicate with the window server at all. Using QtGui is not a problem, though.

QWebPage在内部创建一些QWidget实例.因此,不可能使用QCoreApplication.

QWebPage internally creates some QWidget instances. Thus, using QCoreApplication is not possible.

尽管在创建QApplication实例时,我已经立即获得了MacOSX扩展坞图标.我不想要那个.这也意味着它以某种方式在Cocoa中注册为GUI应用程序.

When creating a QApplication instance though, I already immediately get a MacOSX dock icon. And I don't want that. It also means that it somehow registers itself in Cocoa as a GUI application.

我的问题不仅限于Mac.我想知道Qt是否有官方"方式来做到这一点.只有在没有的情况下,我才想知道执行此操作的具体方法,例如目前在Mac上.

My question is not Mac-only. I would like to know if there is an "official" way for Qt to do this. Only if there is not, I would like to know specific ways to do this, e.g. on Mac for now.

关于Mac的更多细节:

Somewhat more specific about Mac:

还有 LSBackgroundOnly 属性,可以为应用包设置该属性,朝着我想要的方向发展(因此,我仍然不确定它是否真的仅用于控制台,例如,在没有Quartz的情况下也可以工作).但是,我根本没有应用程序捆绑包;它只是一个简单的二进制文件(在shell中用作命令行工具).

There is also the LSBackgroundOnly property which can be set for an App bundle and which goes into the direction to what I want (whereby I'm still not sure if it is really truly console-only, e.g. would also work without Quartz, etc.). However, I don't have an App bundle at all; it's just a simple binary (to be used as a command-line-tool in shells).

目前,我有一个小的解决方法来隐藏停靠图标,但这很丑陋,因为它首先弹出然后消失:(Python代码,但这并不重要...)

For now, I have a small workaround to hide the dock icon but that is quite ugly as it first pops up and then goes aways: (Python code but that doesn't really matter...)

def hideMacDockIcon():
    # http://stackoverflow.com/a/9220857/133374
    import AppKit
    # https://developer.apple.com/library/mac/#documentation/AppKit/Reference/NSRunningApplication_Class/Reference/Reference.html
    NSApplicationActivationPolicyRegular = 0
    NSApplicationActivationPolicyAccessory = 1
    NSApplicationActivationPolicyProhibited = 2
    AppKit.NSApp.setActivationPolicy_(NSApplicationActivationPolicyProhibited)

app = QApplication(sys.argv)
if sys.platform == "darwin":
    hideMacDockIcon()

此外,我不确定它是否也可以在其他环境中使用,例如作为系统守护程序.

Also, I'm not sure if it also works in other environments, maybe as a system daemon or so.

推荐答案

您可以使用QPA进行此操作.这恰好是PhantomJS实现无头的方式.修改了QT预配置文件以指定QPA:

You can do this with QPA. This happens to be how PhantomJS achieved headlessness. The QT preconfig file was modified to specify QPA:

QT_CFG +=' -qpa' # X11-less with QPA (aka Lighthouse)

QT_CFG +=' -qpa' # X11-less with QPA (aka Lighthouse)

关于QMinimalWindowSurface的一些知识.

Also something about QMinimalWindowSurface.

https://github.com/ariya/phantomjs/commit/6c8a1c2dc1 https://github.com/ariya/phantomjs/commit/c78ae190a9

这篇关于如何在非GUI应用程序中使用QWebPage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆