Headless mode fails with qt 5.7

Bug #1627494 reported by Hans de Goede
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
calibre
Invalid
Undecided
Unassigned

Bug Description

Hi,

Headless mode (and book import from the gui which seems to depend on headless mode for some books) fails when using qt 5.7 (with the Fedora calibre-2.68.0 pkgs on Fedora 25), the error reported is:

"
This application failed to start because it could not find or load the Qt platform plugin "headless"
in "/usr/lib64/calibre/calibre/plugins".

Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, xcb.

Reinstalling the application may fix this problem.
"

I've managed to hack around this (fixing using calibre under X at least) with this:

--- /usr/lib64/calibre/calibre/gui2/__init__.py~ 2016-09-17 17:58:30.000000000 +0200
+++ /usr/lib64/calibre/calibre/gui2/__init__.py 2016-09-25 15:02:29.831338885 +0200
@@ -876,10 +876,7 @@
         self.file_event_hook = None
         if override_program_name:
             args = [override_program_name] + args[1:]
- if headless:
- if not args:
- args = sys.argv[:1]
- args.extend(['-platformpluginpath', sys.extensions_location, '-platform', 'headless'])
+ headless = False
         self.headless = headless
         qargs = [i.encode('utf-8') if isinstance(i, unicode) else i for i in args]
         self.pi = plugins['progress_indicator'][0]
@@ -1186,6 +1183,7 @@
 _ea_lock = Lock()

 def ensure_app(headless=True):
+ headless = False
     global _store_app
     with _ea_lock:
         if _store_app is None and QApplication.instance() is None:

Which allows me to import books again. I realize this is a useless fix, but it proves that the problem is with headless and that calibre works fine otherwise.

Revision history for this message
Kovid Goyal (kovid) wrote : Re: calibre bug 1627494

Works fine for me with Qt 5.7.0 on Arch. You want to debug why it is
not working on your machine, you should use the Qt env var to debug
plugin loading, IIRC it was something like QT_DEBUG_PLUGINS

Do,

QT_DEBUG_PLUGINS=1 calibre-debug -c "from calibre.gui2 import *; ensure_app()"

That gives me

QFactoryLoader::QFactoryLoader() looking at "/home/kovid/work/calibre/src/calibre/plugins/libheadless.so"
Found metadata in lib /home/kovid/work/calibre/src/calibre/plugins/libheadless.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "headless"
        ]
    },
    "className": "HeadlessIntegrationPlugin",
    "debug": false,
    "version": 329472
}

Got keys from plugin meta data ("headless")

Most likely you just need to recompile the headless plugin.

  status invalid

Changed in calibre:
status: New → Invalid
Revision history for this message
Hans de Goede (j-w-r-degoede) wrote :

Hi,

I already tried to rebuild calibre from source before filing the bug, unfortunately that does not fix it.

Thanks for the debug command, that gives a lot of output in my case, but the useful bit is:

Found metadata in lib /usr/lib64/calibre/calibre/plugins/libheadless.so, metadat
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.2",
    "MetaData": {
        "Keys": [
            "headless"
        ]
    },
    "className": "HeadlessIntegrationPlugin",
    "debug": false,
    "version": 329472
}

Note the Interface.5.2 bit which should be Interface.5.3. For some reason the #if to determine which interface to put in the metadata is not working when building on Fedora 25. I'm investigating further now ...

Regards,

Hans

Changed in calibre:
status: Invalid → New
Revision history for this message
Hans de Goede (j-w-r-degoede) wrote :

Hi again,

I can confirm that removing the #if on QT_VERSION and unstead unconditionally using the Interface.5.3 metadata fixes things. At first I was thinking that the problem might be a missing "include <qtGlobal>" in src/calibre/headless/main.cpp but that is not it. No idea what is causing this problem I'm afraid.

Regards,

Hans

Revision history for this message
Hans de Goede (j-w-r-degoede) wrote :

Hi,

Ok last comment, I tried to get pre-processor output by adding -save-temps to OVERRIDE_CFLAGS, but it seems that the override CFLAGS get ignored when building the headless plugin, that may (in some weird way) be the cause of this, and fixing this would be a good idea in general.

Regards,

Hans

Revision history for this message
Kovid Goyal (kovid) wrote :

That comes from
/usr/include/qt/QtGui/5.7.0/QtGui/qpa/qplatformintegrationplugin.h (or
wherever the header file is located on your system). If you are getting
an incorrect value, it means you likely have a mix of Qt versions on
your system. Clean them out and make sure the only one is Qt 5.7.0 and
you should be fine.

 status invalid

Changed in calibre:
status: New → Invalid
Revision history for this message
Kovid Goyal (kovid) wrote :

And note that OVERRIDE_CFLAGS has nothing to do with this. It's purpose is to allow you to override the cflags used by the calibre build system. Qt plugins are built using qmake (the calibre build system delegates to that), so the cflags the calibre build system uses do not come into the picture at all.

Revision history for this message
Kovid Goyal (kovid) wrote :

Also, I just committed a code to get rid of the #if since it is not really needed.

Revision history for this message
Kovid Goyal (kovid) wrote :

But note that there are lots of other QT_VERSION checks, so other things will break if you have a mixture of qt versions on your system.

Revision history for this message
Hans de Goede (j-w-r-degoede) wrote :

I do not have a mixture of qt versions on my system and the official Fedora pkgs which get build in a freshly generated buildroot with just qt5.7 in there certainly do not.

For some reason the #if check is failing. With your commit removing that #if check things do work, so that does fix things, but this is still word. Some Google results say that the #if may not play well with moc.

Revision history for this message
Hans de Goede (j-w-r-degoede) wrote :

s/word/weird/ in my previous comment.

Revision history for this message
Kovid Goyal (kovid) wrote :

In any case, since the problem is solved, I am not spending more time on
this :)

Revision history for this message
Hans de Goede (j-w-r-degoede) wrote :

Understood, thank you for your help with resolving this.

Revision history for this message
Michele Locati (mlocati) wrote :

I've seen this error too on WSL.
I'm on Windows 10 build 15063 (Creators Update). With a clean Ubuntu 16.04.2 LTS, I run these commands:

$ sudo apt-get install mesa-utils
$ wget -nv -O- https://download.calibre-ebook.com/linux-installer.py | python3 -c "import sys; main=lambda x,y:sys.stderr.write('Download failed\n'); exec(sys.stdin.read()); main('.', True)"
$ calibre/ebook-convert input.epub output.mobi -v

Conversion options changed from defaults:
  verbose: 1
1% Converting input to HTML...
InputFormatPlugin: EPUB Input running
on input.epub
Found HTML cover OEBPS/Text/titlepage.xhtml
Parsing all content...
Parsing OEBPS/Text/index0000.html ...
[...]
Reading TOC from NCX...
34% Running transforms on e-book...
Merging user specified metadata...
Detecting structure...
Flattening CSS and remapping font sizes...
Source base font size is 12.00000pt
Removing fake margins...
Found 785 items of level: p_1
Found 6 items of level: div_1
p_1 left margin stats: Counter({u'0': 785})
p_1 right margin stats: Counter({u'0': 785})
div_1 left margin stats: Counter()
div_1 right margin stats: Counter()
Cleaning up manifest...
Trimming unused files from manifest...
Trimming u'OEBPS/Text/titlepage.xhtml' from manifest
Creating MOBI Output...
67% Running MOBI Output plugin
Serializing resources...
Creating MOBI 6 output
Generating in-line TOC...
Applying case-transforming CSS...
Parsing manglecase.css ...
Parsing tocstyle.css ...
This application failed to start because it could not find or load the Qt platform plugin "headless"
in "calibre/lib/python2.7/site-packages/calibre/plugins".

Available platform plugins are: headless (from calibre/lib/python2.7/site-packages/calibre/plugins), linuxfb, minimal, offscreen, xcb.

Reinstalling the application may fix this problem.
Aborted (core dumped)

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.