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

make CVV module work with Qt6 #3285

Merged
merged 6 commits into from
Nov 16, 2022
Merged

make CVV module work with Qt6 #3285

merged 6 commits into from
Nov 16, 2022

Conversation

bebuch
Copy link
Contributor

@bebuch bebuch commented Jun 16, 2022

OpenCV can be compiled against Qt5 and Qt6. The Contrib CVV module depends on Qt5 and has received an incomplete patch with #3072 that allows configuring but not compiling. CVV previously used some features that were deprecated in Qt5 and removed in Qt6.

This patch replaces the corresponding lines in the source code with functions that work in Qt5.15 LTS and Qt6.

This does fix the Issue #3146.

Note: CVV still uses QRegExp which can not directly replaced by QRegularExpression. Therefor Qt6 moved QRegExp to the module Core5Compat, which requires a find_package because it is not required by OpenCV main project.

Pull Request Readiness Checklist

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
    • This is a bug fix without additional tests.
    • It would be useful to add a CI pipeline which builds against Qt6 or even better to change the current pipelines to build against Qt6 by default, since Qt5 is out of support except for commercial users.
  • The feature is well documented and sample code can be built with the project CMake
force_builders=linux,docs,custom
build_image:Custom=qt:16.04
buildworker:Custom=linux-1

@bebuch
Copy link
Contributor Author

bebuch commented Jul 4, 2022

Is there anything wrong with the PR that running workflows are not approved?

@asenyaev
Copy link
Contributor

Hi @bebuch!

I have tested your changes building OpenCV with Qt5 and Qt6. Qt6 does not have any issues during the build, but OpenCV cannot be compiled using Qt5 (5.12.8).

Steps to reproduce:

  1. Clone OpenCV and OpenCV Contrib
git clone --branch 4.x https://github.com/opencv/opencv.git
git clone --branch 4.x https://github.com/opencv/opencv_contrib.git
  1. Add changes from this PR:
cd opencv_contrib && git pull -v "https://github.com/bebuch/opencv_contrib" "4.x" && cd ..
  1. Run CMake:
cmake -B build -DOPENCV_EXTRA_MODULES_PATH=opencv_contrib/modules -DBUILD_DOCS=ON -DPYTHON_DEFAULT_EXECUTABLE=/usr/bin/python3 -DOPENCV_ENABLE_NONFREE=ON -DWITH_QT=ON opencv
  1. Compile OpenCV:
cmake --build build --target install
Qt5 output

...
[ 56%] Building CXX object modules/cvv/CMakeFiles/opencv_cvv.dir/opencv_cvv_autogen/mocs_compilation.cpp.o
In file included from /opencv_contrib/modules/cvv/src/gui/overview_panel.hpp:12,
                 from /opencv_contrib/modules/cvv/src/gui/main_call_window.hpp:9,
                 from /build/modules/cvv/opencv_cvv_autogen/MXUWEOXILK/moc_main_call_window.cpp:9,
                 from /build/modules/cvv/opencv_cvv_autogen/mocs_compilation.cpp:6:
/opencv_contrib/modules/cvv/src/gui/../stfl/stfl_engine.hpp: In member function 'std::vector<cvv::stfl::ElementGroup<Element> > cvv::stfl::STFLEngine<Element>::query(QString)':
/opencv_contrib/modules/cvv/src/gui/../stfl/stfl_engine.hpp:165:28: error: 'SkipEmptyParts' is not a member of 'Qt'
  165 |       query.split("#", Qt::SkipEmptyParts);
      |                            ^~~~~~~~~~~~~~
/opencv_contrib/modules/cvv/src/gui/../stfl/stfl_engine.hpp: In member function 'QList<T> cvv::stfl::STFLEngine<Element>::executeFilters(const QList<T>&, const QStringList&)':
/opencv_contrib/modules/cvv/src/gui/../stfl/stfl_engine.hpp:552:33: error: 'SkipEmptyParts' is not a member of 'Qt'
  552 |        cmdString.split(" ", Qt::SkipEmptyParts);
      |                                 ^~~~~~~~~~~~~~
/opencv_contrib/modules/cvv/src/gui/../stfl/stfl_engine.hpp:573:18: error: 'SkipEmptyParts' is not a member of 'Qt'
  573 |         ",", Qt::SkipEmptyParts);
      |                  ^~~~~~~~~~~~~~
/opencv_contrib/modules/cvv/src/gui/../stfl/stfl_engine.hpp: In member function 'QList<T> cvv::stfl::STFLEngine<Element>::executeSortCmds(const QList<T>&, const QStringList&)':
/opencv_contrib/modules/cvv/src/gui/../stfl/stfl_engine.hpp:612:33: error: 'SkipEmptyParts' is not a member of 'Qt'
  612 |        cmdString.split(" ", Qt::SkipEmptyParts);
      |                                 ^~~~~~~~~~~~~~
/opencv_contrib/modules/cvv/src/gui/../stfl/stfl_engine.hpp:622:39: error: 'SkipEmptyParts' is not a member of 'Qt'
  622 |    arr = arr.join(" ").split(",", Qt::SkipEmptyParts);
      |                                       ^~~~~~~~~~~~~~
/opencv_contrib/modules/cvv/src/gui/../stfl/stfl_engine.hpp: In member function 'std::vector<cvv::stfl::ElementGroup<Element> > cvv::stfl::STFLEngine<Element>::executeGroupCmds(const QList<T>&, const QStringList&)':
/opencv_contrib/modules/cvv/src/gui/../stfl/stfl_engine.hpp:678:33: error: 'SkipEmptyParts' is not a member of 'Qt'
  678 |        cmdString.split(" ", Qt::SkipEmptyParts);
      |                                 ^~~~~~~~~~~~~~
/opencv_contrib/modules/cvv/src/gui/../stfl/stfl_engine.hpp:692:38: error: 'SkipEmptyParts' is not a member of 'Qt'
  692 |    arr = arr.join("").split(",", Qt::SkipEmptyParts);
      |                                      ^~~~~~~~~~~~~~
/opencv_contrib/modules/cvv/src/gui/../stfl/stfl_engine.hpp:723:35: error: 'SkipEmptyParts' is not a member of 'Qt'
  723 |        it->first.split("\\|", Qt::SkipEmptyParts),
      |                                   ^~~~~~~~~~~~~~
/opencv_contrib/modules/cvv/src/gui/../stfl/stfl_engine.hpp: In member function 'void cvv::stfl::STFLEngine<Element>::executeAdditionalCommands(std::vector<cvv::stfl::ElementGroup<Element> >&, QStringList)':
/opencv_contrib/modules/cvv/src/gui/../stfl/stfl_engine.hpp:736:33: error: 'SkipEmptyParts' is not a member of 'Qt'
  736 |        cmdString.split(" ", Qt::SkipEmptyParts);
      |                                 ^~~~~~~~~~~~~~
/opencv_contrib/modules/cvv/src/gui/../stfl/stfl_engine.hpp:746:38: error: 'SkipEmptyParts' is not a member of 'Qt'
  746 |    arr = arr.join("").split(",", Qt::SkipEmptyParts);
      |                                      ^~~~~~~~~~~~~~
/opencv_contrib/modules/cvv/src/gui/../stfl/stfl_engine.hpp: In member function 'QStringList cvv::stfl::STFLEngine<Element>::getSuggestionsForCmdQuery(const QString&, size_t)':
/opencv_contrib/modules/cvv/src/gui/../stfl/stfl_engine.hpp:765:62: error: no matching function for call to 'min(qsizetype, int)'
  765 |        std::min(qsizetype(hasByString ? 2 : 1), tokens.size());
      |                                                              ^
In file included from /usr/include/c++/9/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
                 from /opencv_contrib/modules/cvv/src/gui/call_tab.hpp:4,
                 from /build/modules/cvv/opencv_cvv_autogen/MXUWEOXILK/moc_call_tab.cpp:9,
                 from /build/modules/cvv/opencv_cvv_autogen/mocs_compilation.cpp:2:
/usr/include/c++/9/bits/stl_algobase.h:198:5: note: candidate: 'template<class _Tp> const _Tp& std::min(const _Tp&, const _Tp&)'
  198 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:198:5: note:   template argument deduction/substitution failed:
In file included from /opencv_contrib/modules/cvv/src/gui/overview_panel.hpp:12,
                 from /opencv_contrib/modules/cvv/src/gui/main_call_window.hpp:9,
                 from /build/modules/cvv/opencv_cvv_autogen/MXUWEOXILK/moc_main_call_window.cpp:9,
                 from /build/modules/cvv/opencv_cvv_autogen/mocs_compilation.cpp:6:
/opencv_contrib/modules/cvv/src/gui/../stfl/stfl_engine.hpp:765:62: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
  765 |        std::min(qsizetype(hasByString ? 2 : 1), tokens.size());
      |                                                              ^
In file included from /usr/include/c++/9/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
                 from /opencv_contrib/modules/cvv/src/gui/call_tab.hpp:4,
                 from /build/modules/cvv/opencv_cvv_autogen/MXUWEOXILK/moc_call_tab.cpp:9,
                 from /build/modules/cvv/opencv_cvv_autogen/mocs_compilation.cpp:2:
/usr/include/c++/9/bits/stl_algobase.h:246:5: note: candidate: 'template<class _Tp, class _Compare> const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  246 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:246:5: note:   template argument deduction/substitution failed:
In file included from /opencv_contrib/modules/cvv/src/gui/overview_panel.hpp:12,
                 from /opencv_contrib/modules/cvv/src/gui/main_call_window.hpp:9,
                 from /build/modules/cvv/opencv_cvv_autogen/MXUWEOXILK/moc_main_call_window.cpp:9,
                 from /build/modules/cvv/opencv_cvv_autogen/mocs_compilation.cpp:6:
/opencv_contrib/modules/cvv/src/gui/../stfl/stfl_engine.hpp:765:62: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
  765 |        std::min(qsizetype(hasByString ? 2 : 1), tokens.size());
      |                                                              ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
                 from /opencv_contrib/modules/cvv/src/gui/call_tab.hpp:4,
                 from /build/modules/cvv/opencv_cvv_autogen/MXUWEOXILK/moc_call_tab.cpp:9,
                 from /build/modules/cvv/opencv_cvv_autogen/mocs_compilation.cpp:2:
/usr/include/c++/9/bits/stl_algo.h:3450:5: note: candidate: 'template<class _Tp> _Tp std::min(std::initializer_list<_Tp>)'
 3450 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3450:5: note:   template argument deduction/substitution failed:
In file included from /opencv_contrib/modules/cvv/src/gui/overview_panel.hpp:12,
                 from /opencv_contrib/modules/cvv/src/gui/main_call_window.hpp:9,
                 from /build/modules/cvv/opencv_cvv_autogen/MXUWEOXILK/moc_main_call_window.cpp:9,
                 from /build/modules/cvv/opencv_cvv_autogen/mocs_compilation.cpp:6:
/opencv_contrib/modules/cvv/src/gui/../stfl/stfl_engine.hpp:765:62: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  765 |        std::min(qsizetype(hasByString ? 2 : 1), tokens.size());
      |                                                              ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
                 from /opencv_contrib/modules/cvv/src/gui/call_tab.hpp:4,
                 from /build/modules/cvv/opencv_cvv_autogen/MXUWEOXILK/moc_call_tab.cpp:9,
                 from /build/modules/cvv/opencv_cvv_autogen/mocs_compilation.cpp:2:
/usr/include/c++/9/bits/stl_algo.h:3456:5: note: candidate: 'template<class _Tp, class _Compare> _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3456 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
In file included from /opencv_contrib/modules/cvv/src/gui/overview_panel.hpp:12,
                 from /opencv_contrib/modules/cvv/src/gui/main_call_window.hpp:9,
                 from /build/modules/cvv/opencv_cvv_autogen/MXUWEOXILK/moc_main_call_window.cpp:9,
                 from /build/modules/cvv/opencv_cvv_autogen/mocs_compilation.cpp:6:
/opencv_contrib/modules/cvv/src/gui/../stfl/stfl_engine.hpp:765:62: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  765 |        std::min(qsizetype(hasByString ? 2 : 1), tokens.size());
      |                                                              ^
/opencv_contrib/modules/cvv/src/gui/../stfl/stfl_engine.hpp:766:37: error: 'SkipEmptyParts' is not a member of 'Qt'
  766 |    tokens = cmdQuery.split(" ", Qt::SkipEmptyParts)
      |                                     ^~~~~~~~~~~~~~
/opencv_contrib/modules/cvv/src/gui/../stfl/stfl_engine.hpp:769:17: error: 'SkipEmptyParts' is not a member of 'Qt'
  769 |        ",", Qt::SkipEmptyParts);
      |                 ^~~~~~~~~~~~~~
/opencv_contrib/modules/cvv/src/gui/../stfl/stfl_engine.hpp:809:18: error: 'SkipEmptyParts' is not a member of 'Qt'
  809 |         ",", Qt::SkipEmptyParts);
      |                  ^~~~~~~~~~~~~~
In file included from /opencv_contrib/modules/cvv/src/gui/overview_panel.hpp:12,
                 from /opencv_contrib/modules/cvv/src/gui/main_call_window.hpp:9,
                 from /build/modules/cvv/opencv_cvv_autogen/MXUWEOXILK/moc_main_call_window.cpp:9,
                 from /build/modules/cvv/opencv_cvv_autogen/mocs_compilation.cpp:6:
/opencv_contrib/modules/cvv/src/gui/../stfl/stfl_engine.hpp: In member function 'void cvv::stfl::STFLEngine<Element>::addQueryToStore(QString)':
/opencv_contrib/modules/cvv/src/gui/../stfl/stfl_engine.hpp:1025:43: error: 'SkipEmptyParts' is not a member of 'Qt'
 1025 |   QStringList cmds = query.split("#", Qt::SkipEmptyParts);
      |                                           ^~~~~~~~~~~~~~
/opencv_contrib/modules/cvv/src/gui/../stfl/stfl_engine.hpp: In member function 'QStringList cvv::stfl::STFLEngine<Element>::sortStringsByStringEquality(const QStringList&, QString)':
/opencv_contrib/modules/cvv/src/gui/../stfl/stfl_engine.hpp:1085:34: error: 'SkipEmptyParts' is not a member of 'Qt'
 1085 |       compareWith.split(" ", Qt::SkipEmptyParts);
      |                                  ^~~~~~~~~~~~~~
/opencv_contrib/modules/cvv/src/gui/../stfl/stfl_engine.hpp:1090:28: error: 'SkipEmptyParts' is not a member of 'Qt'
 1090 |         str.split(" ", Qt::SkipEmptyParts))
      |                            ^~~~~~~~~~~~~~
make[2]: *** [modules/cvv/CMakeFiles/opencv_cvv.dir/build.make:63: modules/cvv/CMakeFiles/opencv_cvv.dir/opencv_cvv_autogen/mocs_compilation.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:6735: modules/cvv/CMakeFiles/opencv_cvv.dir/all] Error 2
make: *** [Makefile:163: all] Error 2

@bebuch
Copy link
Contributor Author

bebuch commented Jul 29, 2022

Thanks for the feedback! I'm currently on vacation and will look into it in the second half of August. ;-)

@asmorkalov
Copy link
Contributor

@bebuch friendly reminder.

@bebuch
Copy link
Contributor Author

bebuch commented Sep 6, 2022

In fact I had forgotten, thanks for reminding me! :-)

@bebuch
Copy link
Contributor Author

bebuch commented Sep 6, 2022

Question: What is the minimal Qt5 version we need to support? 5.12 LTS is out of support, do we still need to support it in the most current OpenCV?

Qt::SkipEmptyParts was introduced in Qt 5.14 while its counterpart QString::SkipEmptyParts was deprecated in 5.15 LTS and removed in 6.0. If we want to support very old Qt versions in the newest OpenCV, I have to implement a workaround for that.

@asmorkalov
Copy link
Contributor

@bebuch we usually relay on popular Linux distributions like Ubuntu, RHEL, Fedora. In case if the popular distros (LTS) provide unsupported version of QT it makes sense to fix the code.

@bebuch
Copy link
Contributor Author

bebuch commented Sep 6, 2022

Okay, that makes Debian Buster (oldstable) with Qt 5.11 probably the oldest one. I will test on its Docker container.

@bebuch
Copy link
Contributor Author

bebuch commented Sep 6, 2022

Ready for the next review.

I tested on Debian 11 with Qt 5.11, Ubuntu 20.04 with Qt 5.12 and Ubuntu 20.04 with Qt 6.3 (Qt source build).

junzhuimx pushed a commit to nxp-imx/meta-imx that referenced this pull request Sep 19, 2022
…ted for Qt6 [YOCIMX-6355]

This is a workaround to get pass the following build error:

/home/bamboo/build/5.15-kirkstone-regression/fsl-imx-internal-xwayland/mx8/yocto/build/tmp/work/armv8a-mx8-poky-linux/opencv/4.6.0.imx-r0/build/
modules/cvv/opencv_cvv_autogen/MXUWEOXILK/../../../../../contrib/modules/cvv/src/gui/call_tab.hpp:4:10: fatal error: QString: No such file or directory

There is a pull request to add Qt6 support in opencv_contrib repo but it is not merged yet.

opencv/opencv_contrib#3285

Signed-off-by: Neena Busireddy <neenareddy.busireddy@nxp.com>
@bebuch
Copy link
Contributor Author

bebuch commented Nov 1, 2022

ping

@asmorkalov asmorkalov self-requested a review November 2, 2022 14:13
@bebuch
Copy link
Contributor Author

bebuch commented Nov 16, 2022

@alalek Thanks for the detailed fixes :-)

And sorry for the delay, last week was busy.

Copy link
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for contribution 👍

@alalek alalek merged commit 1754d03 into opencv:4.x Nov 16, 2022
@alalek alalek mentioned this pull request Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OpenCV 4.5.5 building CVV module fails with Qt6 selected
4 participants