Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qt6 QtCore.QRegularExpression not available in Qt.py #424

Open
sylvainberger opened this issue Nov 6, 2024 · 2 comments
Open

Qt6 QtCore.QRegularExpression not available in Qt.py #424

sylvainberger opened this issue Nov 6, 2024 · 2 comments

Comments

@sylvainberger
Copy link

Hi, When I try to import QtCore.QRegularExpression from Qt, I get an error.
Importing directly from PySide6 works.

Example in Python3.11 with PySide6 and Qt.py:
Python 3.11.9 (main, Oct 30 2024, 17:54:48) [GCC 11.3.1 20221121 (Red Hat 11.3.1-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.

from Qt.QtCore import QRegularExpression
Traceback (most recent call last):
File "", line 1, in
ImportError: cannot import name 'QRegularExpression' from 'Qt.QtCore' (unknown location)
from PySide6.QtCore import QRegularExpression
print(QRegularExpression)
<class 'PySide6.QtCore.QRegularExpression'>

@mottosso
Copy link
Owner

mottosso commented Nov 7, 2024

Looks like it's been remapped to QRegExp for backwards compatibility with Qt 4 and 5.

@sylvainberger
Copy link
Author

I can't make it work using QRegEx to get code compatible with Qt5 and Qt6

The best way I found is to do the import in try/except and use QRegularExpression

Example:

try:
    from PySide6.QtCore import QRegularExpression
except:
    from PySide2.QtCore import QRegularExpression

proxy_model = QtCore.QSortFilterProxyModel()
proxy_model.setFilterRegularExpression(QRegularExpression(re_pattern, QRegularExpression.CaseInsensitiveOption))

Any attemps to write compatible code using QRegEx fails in either Qt5 or Qt6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants