juangburgos / QDeferred

Qt C++ alternative for handling async code execution
MIT License
77 stars 16 forks source link

Builds with MSVC19 only with C++20 enabled #9

Open githubuser0xFFFF opened 1 month ago

githubuser0xFFFF commented 1 month ago

Hi,

thank you for this great library. We use it for some time now with MinGW 11 (gcc 11.2) with the qmake config option C++17. Now we switched to MSVC19 compiler an see build issues. The only way to fix these issues is to switch to C++20 for MSVC.

On the project page you write "This library requires C++11." Is this still valid?

This is the code that triggers the compiler error for MSVC:

void CDatabaseConnectionDialog::onCheckConnectionClicked()
{
    auto DbDescr = databaseDescriptor();
    QDeferred<QString> DeferredResult;
    d->ui.statusFrame->setState(CInputStatusWidget::ProcessingState, tr("Checking database connection - please wait..."));
    d->ui.statusFrame->show();
    d->ui.connectButton->setEnabled(false);
    QApplication::setOverrideCursor(Qt::WaitCursor);

    d->Worker.execInThread([DeferredResult, DbDescr]() mutable {
        {
            auto DB = QSqlDatabase::addDatabase(DbDescr.m_Driver, "ConnectionCheck");
            DbDescr.apply(DB);
            bool Result = DB.open();
            QString Message = tr("Database connection successful");
            if (!Result)
            {
                Message = DB.lastError().text();
                DeferredResult.reject(Message);
            }
            else
            {
                DeferredResult.resolve(Message);
            }
        }
        QSqlDatabase::removeDatabase("ConnectionCheck");
    });

    DeferredResult
        .fail([this](QString res) {
            this->setConnectionCheckResult(false, res);
        })
        .done([this](QString res) {
            this->setConnectionCheckResult(true, res);
        });
}

An this is the error:

C:\CodingXP\msvc19_64_qt6\usr\include\QDeferred\qdeferreddata.hpp(680): error C2059: syntax error: ';'
C:\CodingXP\msvc19_64_qt6\usr\include\QDeferred\qdeferreddata.hpp(661): note: while compiling class template member function 'QDeferredData<QString>::DeferredAllCallbacks *QDeferredData<QString>::getCallbacksForThread(void)'
C:\CodingXP\msvc19_64_qt6\usr\include\QDeferred\qdeferreddata.hpp(249): note: see reference to function template instantiation 'QDeferredData<QString>::DeferredAllCallbacks *QDeferredData<QString>::getCallbacksForThread(void)' being compiled
C:\CodingXP\msvc19_64_qt6\usr\include\QDeferred\qdeferreddata.hpp(194): note: while compiling class template member function 'QDeferredData<QString>::QDeferredData(void)'
C:\CodingXP\msvc19_64_qt6\usr\include\QDeferred\qdeferred.hpp(146): note: see reference to function template instantiation 'QDeferredData<QString>::QDeferredData(void)' being compiled
C:\CodingXP\msvc19_64_qt6\usr\include\QDeferred\qdeferred.hpp(147): note: see reference to class template instantiation 'QDeferredData<QString>' being compiled
C:\CodingXP\msvc19_64_qt6\usr\include\QDeferred\qdeferred.hpp(144): note: while compiling class template member function 'QDeferred<QString>::QDeferred(void)'
..\..\..\src\qtlabb\database\DatabaseConnectionDialog.cpp(296): note: see reference to function template instantiation 'QDeferred<QString>::QDeferred(void)' being compiled
..\..\..\src\qtlabb\database\DatabaseConnectionDialog.cpp(296): note: see reference to class template instantiation 'QDeferred<QString>' being compiled
C:\CodingXP\msvc19_64_qt6\usr\include\QDeferred\qdeferreddata.hpp(681): error C2143: syntax error: missing ';' before '}'
C:\CodingXP\msvc19_64_qt6\usr\include\QDeferred\qdeferreddata.hpp(681): error C2059: syntax error: '}'
C:\CodingXP\msvc19_64_qt6\usr\include\QDeferred\qdeferreddata.hpp(683): error C2059: syntax error: 'return'
C:\CodingXP\msvc19_64_qt6\usr\include\QDeferred\qdeferreddata.hpp(684): error C2059: syntax error: '}'
C:\CodingXP\msvc19_64_qt6\usr\include\QDeferred\qdeferreddata.hpp(684): error C2143: syntax error: missing ';' before '}'

When using MinGW with C++17 or when switching to C++20 for MSVC19 compiler, the code compiles fine. That would indicate, that C++ 20 is required instead of C++11.

juangburgos commented 1 month ago

Hi, Wow, first for all, let me say I am a fan of your work (Advanced Docking System). I did not know this project was (still) used. I stopped using it a few years ago because I changed jobs and now I don't use Qt at all. Having said that, I just saw that I had a local branch called vs2019_fixes, which I just pushed here: https://github.com/juangburgos/QDeferred/pull/10 Please check if that works, otherwise I can take a deeper look. These issues are normally compilers (and compiler versions) being picky with templates, is hard to make all of them happy.

githubuser0xFFFF commented 1 month ago

Hi,

Thank you for the hint with the branch. I merged the branch into master but it did not fix the issue. Even compiling the libray itself with MSVC19 requires CONFIG += c++20. Compiling your library with CONFIG += c++17 triggers the following error:

C:\CodingXP\cetoni_third_party\QDeferred\src\qdeferreddata.hpp(681): error C2059: syntax error: ';'
C:\CodingXP\cetoni_third_party\QDeferred\src\qdeferreddata.hpp(662): note: while compiling class template member function 'QDeferredData<>::DeferredAllCallbacks *QDeferredData<>::getCallbacksForThread(void)'
C:\CodingXP\cetoni_third_party\QDeferred\src\qdeferreddata.hpp(250): note: see reference to function template instantiation 'QDeferredData<>::DeferredAllCallbacks *QDeferredData<>::getCallbacksForThread(void)' being compiled
C:\CodingXP\cetoni_third_party\QDeferred\src\qdeferreddata.hpp(195): note: while compiling class template member function 'QDeferredData<>::QDeferredData(void)'
C:\CodingXP\cetoni_third_party\QDeferred\src\qdeferred.hpp(146): note: see reference to function template instantiation 'QDeferredData<>::QDeferredData(void)' being compiled
C:\CodingXP\cetoni_third_party\QDeferred\src\qdeferred.hpp(144): note: while compiling class template member function 'QDeferred<>::QDeferred(void)'
..\..\QDeferred\src\qlambdathreadworkerdata.cpp(159): note: see reference to function template instantiation 'QDeferred<>::QDeferred(void)' being compiled
C:\CodingXP\cetoni_third_party\QDeferred\src\qdeferred.hpp(368): note: see reference to class template instantiation 'QDeferred<>' being compiled
C:\CodingXP\cetoni_third_party\QDeferred\src\qdeferreddata.hpp(682): error C2143: syntax error: missing ';' before '}'
C:\CodingXP\cetoni_third_party\QDeferred\src\qdeferreddata.hpp(682): error C2059: syntax error: '}'
C:\CodingXP\cetoni_third_party\QDeferred\src\qdeferreddata.hpp(684): error C2059: syntax error: 'return'
C:\CodingXP\cetoni_third_party\QDeferred\src\qdeferreddata.hpp(685): error C2059: syntax error: '}'
C:\CodingXP\cetoni_third_party\QDeferred\src\qdeferreddata.hpp(685): error C2143: syntax error: missing ';' before '}'

If the project is not actively developed anymore I will stay with CONFIG += c++20. Thank you for your response.