Results 1 to 4 of 4

Thread: Open odt files via Qt and Libreoffice api

  1. #1
    Join Date
    Apr 2006
    Location
    Saint-Petersburg, Russia
    Posts
    63
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default 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 ?
    Best regards,
    Yuriy Rusinov.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,481
    Thanks
    252
    Thanked 712 Times in 702 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default 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.
    Last edited by d_stranz; 26th March 2020 at 17:06.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. The following user says thank you to d_stranz for this useful post:

    YuriyRusinov (27th March 2020)

  4. #3
    Join Date
    Apr 2006
    Location
    Saint-Petersburg, Russia
    Posts
    63
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default 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
    Qt Code:
    1. int nlen=fileUrl.toString().size();
    2. OUStringBuffer buf;
    3. for (int i=0; i<nlen; i++)
    4. buf.append( fileUrl.toString().toStdString().at(i) );
    To copy to clipboard, switch view to plain text mode 
    Last edited by YuriyRusinov; 27th March 2020 at 10:35.
    Best regards,
    Yuriy Rusinov.

  5. #4
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    491
    Thanked 73 Times in 69 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Open odt files via Qt and Libreoffice api

    Quote Originally Posted by YuriyRusinov View Post
    Qt Code:
    1. int nlen=fileUrl.toString().size();
    2. OUStringBuffer buf;
    3. for (int i=0; i<nlen; i++)
    4. buf.append( fileUrl.toString().toStdString().at(i) );
    To copy to clipboard, switch view to plain text mode 
    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

    Qt Code:
    1. const QByteArray ba = fileUrl.toString().toUtf8()
    2. OString ostr = OString(ba.data(), ba.size());
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. I can't open old projects / cpp files.
    By mirek_zaklosa in forum Newbie
    Replies: 3
    Last Post: 8th June 2019, 16:41
  2. tutorial about qt and LibreOffice Base
    By Saurian in forum Newbie
    Replies: 1
    Last Post: 28th April 2012, 10:24
  3. Open odt files with Qt
    By Qiieha in forum Qt Programming
    Replies: 2
    Last Post: 21st April 2011, 09:29
  4. qca, qca-gnupg Not able to open files
    By sky in forum Newbie
    Replies: 1
    Last Post: 15th February 2011, 06:11
  5. open files in different windows
    By ramaha8319 in forum Qt Tools
    Replies: 1
    Last Post: 27th April 2009, 14:27

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.