How to use QWebPage in an application without a GUI

I want to use QWebPage in an application other than the Qt GUI. By this I mean that I generally do not want to communicate with the window server. However, using QtGui is not a problem.

QWebPage internally creates multiple QWidget instances. Therefore, using QCoreApplication not possible.

When creating the QApplication instance, although I already got the MacOSX dock icon right away. And I do not want this. It also means that it is somehow registered with Cocoa as a graphical application.

My question is not only for Mac. I would like to know if there is an β€œofficial” way for Qt to do this. Only if this does not happen, I would like to know specific ways to do this, for example. on the Mac at the moment.


Somewhat more specifically about the Mac:

There is also the LSBackgroundOnly property, which can be set for the application package and which goes in the direction of what I want (whereby I'm still not sure if it really is a console, for example, it will also work without Quartz, etc.) . However, I do not have an application package; it's just a simple binary (which will be used as a command line in shells).

Right now I have a little workaround to hide the dock icon, but it's pretty ugly as it first appears and then goes forward: (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, perhaps as a system daemon or so.

+4
source share
6 answers

You can do this with QPA. This is how PhantomJS achieved headlessness. The QT preconfig file has been modified to indicate QPA:

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

Also something about QMinimalWindowSurface.

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

+5
source

QApplication initializes the static variables that are used by QWidgets. Thus, you cannot create any widgets until you create an instance of QApplication.

If you need a browser, try using Webkit , Chromium , Berkelium , Awesomium (commersial) or chromiumoffscreenrenderer (LGPL fork)

+4
source

Have you tried passing the "no gui" flag to QApplication?

 QApplication ( int & argc, char ** argv, bool GUIenabled ) 
+1
source

What do you want to use QWebPage for? Maybe the class is better suited to your needs?
If not: copying and pasting from QWebPage source code is an option.

Update:
Do you want to create something like a command line browser? Or just something like a browser on a web server?
In these cases, you can simply hide the QWidget so that nothing is displayed in the dock panel (I'm not sure that this works in OS X, and in Windows there may be windows without recording in the taskbar, I think).

0
source

I am afraid there is no easy way not to use QtGui. If you look at the source code of QWebPage , you will see that QPainter is used, like some exported methods \ objects from QtGui. This was expected because the API has features such as QWidget* QWebPage::view() const .

You can crack the source code, but your Qt libraries are unique and incompatible. This is a burden.

0
source

PyPhantomJs is a mute web browser using pyqt, and even IT uses QApplication: http://code.google.com/p/phantomjs/source/browse/python/pyphantomjs/pyphantomjs.py?name=4ec8df3a84&r=4dc051a60ec3d59bf125824aacacacacaca

You can always simply use the various window flags that make the application run as an application in the system tray

Update

since I see that you are using osx, you can add this parameter to your application tablet so that it starts as a system service without icons: http://www.cocoadev.com/index.pl?LSBackgroundOnly

I use this for an application which is in the taskbar at the top and provides a spotlight style interface

0
source

Source: https://habr.com/ru/post/1395617/


All Articles