Bug 486171 - Doesn't actually work with Qt 6
Summary: Doesn't actually work with Qt 6
Status: RESOLVED FIXED
Alias: None
Product: kajongg
Classification: Applications
Component: general (other bugs)
Version First Reported In: 24.02.2
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Wolfgang Rohdewald
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-04-26 19:51 UTC by Antonio Rojas
Modified: 2024-09-11 10:06 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In: 24.05
Sentry Crash Report:


Attachments
Patch for running with Pyside (823 bytes, patch)
2024-09-10 16:56 UTC, Wolfgang Rohdewald
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Antonio Rojas 2024-04-26 19:51:29 UTC
kajongg claims to support Qt6, and in fact depends on it at build time, but it doesn't actually work with it

Traceback (most recent call last):
  File "/usr/share/kajongg/kdestub.py", line 100, in desktopSize
    result = Internal.app.desktop().availableGeometry()
             ^^^^^^^^^^^^^^^^^^^^
AttributeError: 'KApplication' object has no attribute 'desktop'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/kajongg", line 185, in <module>
    from mainwindow import MainWindow
  File "/usr/share/kajongg/mainwindow.py", line 89, in <module>
    logError("\n".join(" * %s" % s for s in NOTFOUND), showStack=False)
  File "/usr/share/kajongg/log.py", line 213, in logError
    return logMessage(msg, logging.ERROR, True, showStack=showStack, withGamePrefix=withGamePrefix)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/share/kajongg/log.py", line 202, in logMessage
    return Information(msg) if prio == logging.INFO else Sorry(msg, always=True)
                                                         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/share/kajongg/dialogs.py", line 201, in __init__
    dialog = Prompt(msg, icon=QMessageBox.Information,
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/share/kajongg/dialogs.py", line 85, in __init__
    KMessageBox.createKMessageBox(
  File "/usr/share/kajongg/kdestub.py", line 209, in createKMessageBox
    desktop = KApplication.desktopSize()
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/share/kajongg/kdestub.py", line 103, in desktopSize
    result = Internal.mainWindow.screen().availableGeometry()
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'screen'
Comment 1 Wolfgang Rohdewald 2024-04-26 22:06:53 UTC
Others wanting to test this might have to set the shell variable QT_API=pyqt6 before starting  kajongg because PyQt5 will be used if installed, see https://github.com/spyder-ide/qtpy

Please double check if you are using the unmodified 24.02.2. The line numbers in the Traceback do not match that version.

One possible problem is the kajonggserver.py process. Even if you finish kajongg, the server process will wait for some time for new clients before exiting. So maybe your kajonggserver.py process was not running the version you thought it does. 

So - please always kill all kajongg processes after changing source code.

One strange thing is that nobody ever reported a bug like 'int' object has no attribute 'split' in clientVersion.split('.'), this only seems to happen to me. So I cherrypicked a fix about this from master to 24.02 so I am actually able to run 24.02.2 - which works fine for me with Qt6.

Your bug should have been fixed with this commit which is part of 24.02.2:

commit 3af0e1c6944695d5bdaf1bd7490cb4ad6ad98665
Author: Wolfgang Rohdewald <wolfgang@rohdewald.de>
Date:   Sat Sep 16 19:10:26 2023 +0200

    Qt6: QApplication.desktop() is deprecated, introduce KApplication.desktopSize()
Comment 2 Antonio Rojas 2024-04-27 13:58:25 UTC
Yes, I was using unmodified 24.02.2. Which like line of the backtrace doesn't match according to you?

Anyway, I just upgraded to 24.04.80 and there's a new error

Traceback (most recent call last):
  File "/usr/bin/kajongg", line 20, in <module>
    from kde import KApplication
  File "/usr/share/kajongg/kde.py", line 12, in <module>
    from kdestub import *  # pylint: disable=wildcard-import,unused-wildcard-import
    ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/share/kajongg/kdestub.py", line 241, in <module>
    class KDialog(CaptionMixin, QDialog):
  File "/usr/share/kajongg/kdestub.py", line 262, in KDialog
    def setButtons(self, buttonMask:QDialogButtonBox.StandardButtons) ->None:
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: type object 'QDialogButtonBox' has no attribute 'StandardButtons'. Did you mean: 'standardButtons'?

After fixing this following the suggestion, I get a slightly different variant of the previous error

Traceback (most recent call last):
  File "/usr/bin/kajongg", line 189, in <module>
    from mainwindow import MainWindow
  File "/usr/share/kajongg/mainwindow.py", line 88, in <module>
    logError("\n".join(f" * {s}" for s in NOTFOUND), showStack=False)
  File "/usr/share/kajongg/log.py", line 146, in logError
    return logMessage(msg, logging.ERROR, True, showStack=showStack, withGamePrefix=withGamePrefix)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/share/kajongg/log.py", line 135, in logMessage
    return Information(msg) if prio == logging.INFO else Sorry(msg, always=True)
                                                         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/share/kajongg/dialogs.py", line 199, in __init__
    dialog = Prompt(msg, icon=QMessageBox.Information,
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/share/kajongg/dialogs.py", line 81, in __init__
    KMessageBox.createKMessageBox(
  File "/usr/share/kajongg/kdestub.py", line 216, in createKMessageBox
    desktop = KApplication.desktopSize()
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/share/kajongg/kdestub.py", line 116, in desktopSize
    assert Internal.mainWindow
           ^^^^^^^^^^^^^^^^^^^
AssertionError
Comment 3 Wolfgang Rohdewald 2024-04-30 17:34:03 UTC
Git commit 077da95547d4af35bc4fa6737654d15442c2768f by Wolfgang Rohdewald.
Committed on 30/04/2024 at 07:59.
Pushed by wrohdewald into branch 'release/24.02'.

Qt6 only worked when Qt5 was installed too
FIXED-IN: 24.02.3

M  +2    -15   src/common.py
M  +0    -1    src/kdestub.py
M  +2    -6    src/modeltest.py
M  +31   -1    src/qt.py

https://invent.kde.org/games/kajongg/-/commit/077da95547d4af35bc4fa6737654d15442c2768f
Comment 4 Albert Astals Cid 2024-04-30 22:37:45 UTC
Wolfgang we won't be having a 24.02.3 release, please make sure these commits are in master and release/24.05 (subscribe to kde-devel mailing list if you aren't to get emails about when the branches are created)
Comment 5 Wolfgang Rohdewald 2024-05-01 05:17:08 UTC
(In reply to Albert Astals Cid from comment #4)
> (subscribe to kde-devel mailing list if you aren't to get emails about when the branches are created)

Done, thank you!
Comment 6 Andreas Sturmlechner 2024-09-10 15:44:18 UTC
I don't think this was supposed to make kajongg PyQt[56]-only? We got the following report: https://bugs.gentoo.org/939423
Comment 7 Andreas Sturmlechner 2024-09-10 15:45:27 UTC
(In reply to Andreas Sturmlechner from comment #6)
> I don't think this was supposed to make kajongg PyQt[56]-only? We got the
> following report: https://bugs.gentoo.org/939423
(the gist:
> Will trigger error when PyQt api disabled
> > err: No module named 'PyQt6'
)
Comment 8 Wolfgang Rohdewald 2024-09-10 16:19:09 UTC
I don't have a gentoo account. 

How did he start kajongg? Value of environment variable QT_API must be pyside6. His statement about sip being required is wrong and makes me think he did not set QT_API. See https://github.com/spyder-ide/qtpy?tab=readme-ov-file#requirements

The kajongg source code he points to sets HAVE_SIP to False if neither PyQt6 nor PyQt5 is found.

Is there no traceback? Where does that message appear? Kajongg does not generate it, so it must be Python. So I'd expect a traceback.
Comment 9 Antonio Rojas 2024-09-10 16:41:51 UTC
> The kajongg source code he points to sets HAVE_SIP to False if neither PyQt6
> nor PyQt5 is found.

No, it sets it to false if both QT5 and QT6 are false (which should never happen). You probably want 'if PYQT5' and 'elif PYQT6' instead.
Comment 10 Wolfgang Rohdewald 2024-09-10 16:56:49 UTC
Created attachment 173534 [details]
Patch for running with Pyside
Comment 11 Wolfgang Rohdewald 2024-09-10 16:57:30 UTC
You are right. Does the patch I just added fix it?
Comment 12 Andreas Sturmlechner 2024-09-10 17:18:51 UTC
(In reply to Wolfgang Rohdewald from comment #11)
> You are right. Does the patch I just added fix it?

Testing this myself right now, it does get further than before, but ends up with:

> C:  * Kajongg is not correctly installed: modules: cannot import name 'sip_cast' from 'qt' (/usr/share/kajongg/qt.py)
> Traceback (most recent call last):
>   File "/usr/share/kajongg/kdestub.py", line 115, in desktopSize
>     result = Internal.app.desktop().availableGeometry()
>              ^^^^^^^^^^^^^^^^^^^^
> AttributeError: 'KApplication' object has no attribute 'desktop'
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):
>   File "/usr/bin/kajongg", line 189, in <module>
>     from mainwindow import MainWindow
>   File "/usr/share/kajongg/mainwindow.py", line 88, in <module>
>     logError("\n".join(f" * {s}" for s in NOTFOUND), showStack=False)
>   File "/usr/share/kajongg/log.py", line 146, in logError
>     return logMessage(msg, logging.ERROR, True, showStack=showStack, withGamePrefix=withGamePrefix)
>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>   File "/usr/share/kajongg/log.py", line 135, in logMessage
>     return Information(msg) if prio == logging.INFO else Sorry(msg, always=True)
>                                                          ^^^^^^^^^^^^^^^^^^^^^^^
>   File "/usr/share/kajongg/dialogs.py", line 193, in __init__
>     dialog = Prompt(msg, icon=QMessageBox.Icon.Information,
>              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>   File "/usr/share/kajongg/dialogs.py", line 81, in __init__
>     KMessageBox.createKMessageBox(
>   File "/usr/share/kajongg/kdestub.py", line 216, in createKMessageBox
>     desktop = KApplication.desktopSize()
>               ^^^^^^^^^^^^^^^^^^^^^^^^^^
>   File "/usr/share/kajongg/kdestub.py", line 117, in desktopSize
>     assert Internal.mainWindow
>            ^^^^^^^^^^^^^^^^^^^
> AssertionError
Comment 13 Andreas Sturmlechner 2024-09-10 17:30:50 UTC
And just to make sure: no problems as soon as QtPy was built with PyQt6 support
Comment 14 Antonio Rojas 2024-09-10 17:38:12 UTC
Before the patch, it works for me (with PySide6) if PyQt6-sip is installed (no need to have PyQt6 itself). After the patch, I get the same backtrace as Andreas with or without PyQt6-sip
Comment 15 Andreas Sturmlechner 2024-09-10 18:14:54 UTC
Change from downstream reporter: https://bugs.gentoo.org/939423#c6

> Not sure if this correct but I added sip_cast to `else` block too
> ---
> else:
>     def sip_cast(obj, _type):
>        """hide not so nice things in qt.py"""
>         return False
>     HAVE_SIP = False
> ---
> It launched and About dialog shows PySide6 api in use.
Comment 16 Wolfgang Rohdewald 2024-09-10 20:13:05 UTC
I committed a possible fix. But without seeing the backtrace I can only guess.
Comment 17 Andreas Sturmlechner 2024-09-10 20:16:38 UTC
If you ask me, keeping Qt5 support is adding complexity for no gain. I doubt any distribution is going to package kajongg-24.08 as Qt5-based.
Comment 18 Andreas Sturmlechner 2024-09-11 06:45:41 UTC
(In reply to Wolfgang Rohdewald from comment #16)
> I committed a possible fix. But without seeing the backtrace I can only
> guess.
Your original fix (attached patch in this bug) is still missing.
Comment 19 Wolfgang Rohdewald 2024-09-11 07:12:30 UTC
Right. That patch is not needed.
Comment 20 Andreas Sturmlechner 2024-09-11 10:06:43 UTC
(In reply to Wolfgang Rohdewald from comment #19)
> Right. That patch is not needed.
It is. Otherwise we're back to:

$  kajongg
Traceback (most recent call last):
  File "/usr/bin/kajongg", line 19, in <module>
    from qt import QObject, QCommandLineParser, QCommandLineOption, Qt, QGuiApplication
  File "/usr/share/kajongg/qt.py", line 147, in <module>
    from PyQt6 import sip  # type:ignore[no-redef]
    ^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'PyQt6'