Open odt files via Qt and Libreoffice api
Hello, Colleagues !
I have to read odt files and search tables in them using Qt and Libreoffice api. I open these files using Qt mechanism and receive there URLs as QString or std::string, but the libreoffice api uses there own types such as rtl::OUString, rtl::OString, because I have to use both Qt and Libreoffice types which way these strings can be converted to each others ?
Re: Open odt files via Qt and Libreoffice api
If the Libreoffice API allows you to convert these string types into std:: wstring or std:: string types, these can be further converted into QString / QByteArray. It is possible that the rtl string types are simply alternate names for C++ std string types. You'll have to consult the Libreoffice API docs for that.
Edit: It looks like rtl:: OString might be equivalent to a QByteArray. The rtl:: OString:: getStr() method returns a "sal_Char" pointer, which is simply a char *. So you should be able to directly initialize a QString or QByteArray with this pointer.
Re: Open odt files via Qt and Libreoffice api
I didn't find support std::string or std::wstring in Libreoffice API and do it via append chars to OUStringBuffer
Code:
int nlen=fileUrl.toString().size();
OUStringBuffer buf;
for (int i=0; i<nlen; i++)
buf.append( fileUrl.toString().toStdString().at(i) );
Re: Open odt files via Qt and Libreoffice api
Quote:
Originally Posted by
YuriyRusinov
Code:
int nlen=fileUrl.toString().size();
OUStringBuffer buf;
for (int i=0; i<nlen; i++)
buf.append( fileUrl.toString().toStdString().at(i) );
Do you try to win the 'What's the most inefficient way to convert a string' contest? It does not event work when fileUrl contains non-Latin1 characters.
As d_stranz already mentioned, OString is a char string so I would simply use the ctor which takes a char*: https://www.openoffice.org/api/docs/...l#OString-1240
Code:
OString ostr = OString(ba.data(), ba.size());