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

Compilation Error in xlsxworkbook.cpp When Using CMake with Qt6.8.1 and MSVC-2022 #370

Open
WuMing-dp opened this issue Dec 6, 2024 · 0 comments

Comments

@WuMing-dp
Copy link

Environment:

  • Qt Version: 6.8.1
  • Compiler: MSVC-2022 (64-bit)
  • Build Tools: Qt Creator and CMake

Problem:

When I build the QXlsx library using CMakeLists.txt with Qt Creator, the following code snippet in xlsxworkbook.cpp triggers a compilation error:

AbstractSheet *sheet = addSheet(name, sheetId, type);  
sheet->setSheetState(state);  
if (relationship.target.startsWith("/")) {  
    QString fullPath = QDir::cleanPath(relationship.target.mid(1));  
    sheet->setFilePath(fullPath);  
}  

The error message is as follows:

D:\cad\QXlsx\QXlsx\source\xlsxworkbook.cpp:610: error: C2248: "QString::QString": cannot access private member declared in class "QString"  
D:\Qt\6.8.1\msvc2022_64\include\QtCore/qstring.h(1014): note: see declaration of "QString::QString"  
D:\Qt\6.8.1\msvc2022_64\include\QtGui/qwindowdefs.h(43): note: see declaration of "QString"  

However, when I use the QXlsx.pro file to open and build the same project in Qt Creator, it compiles successfully without any issues.

Observations:

  1. If I comment out the following compile definitions in CMakeLists.txt:

    QT_NO_CAST_TO_ASCII  
    QT_NO_CAST_FROM_ASCII  

    The project compiles successfully even when using CMakeLists.txt.

  2. I want to understand why this error occurs when these definitions are enabled.

  3. I am concerned whether removing QT_NO_CAST_TO_ASCII and QT_NO_CAST_FROM_ASCII will have any negative impact on the code or library behavior.

Questions:

  • Why does the compilation fail when these flags are present?
  • Is it safe to comment out these flags in CMakeLists.txt?

Steps to Reproduce:

  1. Open the QXlsx project with Qt Creator using CMakeLists.txt.
  2. Build the project.
  3. Observe the compilation error at xlsxworkbook.cpp line 610.
  4. Comment out QT_NO_CAST_TO_ASCII and QT_NO_CAST_FROM_ASCII in CMakeLists.txt.
  5. Rebuild the project and notice it compiles successfully.
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

1 participant