0
votes

I am trying to use the library simplexlsxwriter with Qt, however when i try to compile I met the following error on several place in the code :

"cannot convert 'const TCHAR* {aka const wchar_t*}' to 'const char*' for argument '1' to 'size_t strlen(const char*)'"

The line in question is:

bool HasZipSuffix(const TCHAR *fn) { 
    const TCHAR *ext = fn+_tcslen(fn);
}

In order to remove the error i tried the following:

bool HasZipSuffix(const TCHAR *fn) { 
    const char* fn_cc = reinterpret_cast<const char*> (fn);
    const TCHAR *ext = fn+_tcslen(fn_cc );
}

It works, however it introduces a lot of errors (about 3720 issues) during compilations. I use mingw53_32 under Qt.

It is very strange since when i create a simple Makefile as follow:

ROOT_DIR := ./

CXXFLAGS=-MMD -MP -Wall
CXXFLAGS+= -I$(ROOT_DIR)

src = Zip/zip.cpp \
    Xlsx/Chartsheet.cpp \
    Xlsx/Workbook.cpp \
    Xlsx/Worksheet.cpp \
    Xlsx/XlsxHeaders.cpp \
    main.cpp 

includes = Zip/zip.h \
    tchar.h \
    Xlsx/Chartsheet.h \
    Xlsx/SimpleXlsxDef.h \
    Xlsx/Workbook.h \
    Xlsx/Worksheet.h \
    Xlsx/XlsxHeaders.h

object=$(src:.cpp=.o)

%: %.o
    $(LINK.cpp) -o $@ $^ $(LDFLAGS)

main: $(object)

-include $(src:.cpp=.d)

The compilation encountered absolutely no difficulty and I obtain the desired binary. So my question is, why using Qt the conversion from const wchar_t* to const char* throw an error while using "raw" mingw compiler, it does not throw any error ?

1
There are functions to actually convert the underlying data, but you can't just reinterpret_cast between things that are different at a binary level.Kenny Ostrom
I should have not add the reinterpret_cast thing in this question as it is more focused on the reason, why the conversion from const wchar_t* to const char* does not throw any error using mingw32 (with gcc version 5.3) but it throw an error when I use the same very same compiler using Qt ?Schneider Loïc
@SchneiderLoïc: Qt is a red herring. It's just a library. You have other compiler flags, most likely.MSalters

1 Answers

-1
votes

Just add

DEFINES -= UNICODE 

to the .pro file. qmake by default defines -DUNICODE, which clashes with the win32 library.