Washington-University / CiftiLib

C++ Library for reading and writing CIFTI-2 and CIFTI-1 files
BSD 2-Clause "Simplified" License
14 stars 10 forks source link

QString and Glib ustring handle standard C++ string differently #18

Closed kiwifb closed 6 years ago

kiwifb commented 6 years ago

While working on packaging fsl I noticed some differences when I used CiftiLib compiled with QT compared to libxml++. QT is my preferred option as it produce almost compiler warnings, however it was not compatible with the code from fsl using it.

After some analysis the code uses calls of the form inputCifti.openFile(some_standard_C++_string). Glib ustring automatically converts standard C++ strings to ustring but QString doesn't do automatic conversion - you have to explicitly call the method fromStdString (http://doc.qt.io/qt-5/qstring.html#fromStdString).

Since CiftiLib doesn't use either directly but wrap them in AString would it be possible to get the QT implementation of AString to provide automatic conversion from C++ standard string?

coalsont commented 6 years ago

This should be fixed by c183d5c85c132f535e6fca9ec08de9a012e3862e.

AString wasn't really a wrapper, it was a typedef, which can't have conversions added to it (implicit conversions must be members). After running into a few surprises, I managed to use a tricky constructor template to get AString working as a class inheriting from QString without manually copying a bunch of QString constructor signatures. It will be missing the explicit constructors, and any multi-argument constructors, but those probably aren't needed by most code (and when it goes into QT code, like its XML library, it will get cast to a QString and everything will work).