Results 1 to 13 of 13

Thread: How to convert QString to QImage

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: How to convert QString to QImage

    It is the same code you already have, just using a QImage instead of QBitmap.

    QPainter works on any QPaintDevice, QBitmap and QImage are two implementations of that interface.

    Cheers,
    _

  2. #2
    Join Date
    Nov 2014
    Posts
    54
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11
    Thanks
    5

    Default Re: How to convert QString to QImage

    Hi anda_skoa,

    I tried this one with the following code.

    QString filename = "sample.bmp";
    QString format = "bmp";
    QImage img(384,60,QImage::format_MonoLSB);
    img.fill(Qt::white);
    QPainter painter(&img);
    QFont serifFont("Times", 18, QFont::Bold);
    painter.setFont(serifFont);
    painter.setPen(Qt::black);
    QStaticText strText(txtStr);
    strText.setTextFormat(Qt::RichText);
    painter.drawStaticText(10,0,strText);
    painter.save();
    img.save(filename,format.toAscii());
    painter.restore();

    I used QImage in place of QBitmap .But still it is not working in device.
    I think QPainter is gui class so that it is not working.
    so can you provide another alternative solution.

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: How to convert QString to QImage

    What does it mean "not working"?
    Have you changed your application object to QCoreApplication?

    Cheers,
    _

  4. #4
    Join Date
    Nov 2014
    Posts
    54
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11
    Thanks
    5

    Default Re: How to convert QString to QImage

    Hi anda_skoa,

    I changed my application object to QCoreApplication.I didn't get any error in compile time,
    but i am getting error in run time like this

    QScreenLinuxFb::connect: No such file or directory
    Error opening framebuffer device /dev/fb0
    QScreenLinuxFb::connect: No such file or directory
    Error opening framebuffer device /dev/fb0
    QScreenLinuxFb::connect: No such file or directory
    Error opening framebuffer device /dev/fb0
    QScreenLinuxFb::connect: No such file or directory
    Error opening framebuffer device /dev/fb0

    our device don't have any LCD .Can you provide any solution

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: How to convert QString to QImage

    Very strange, the QCoreApplication does not have code to load any QPA plugin, only QGuiApplication does.

    Still, you could try providing the qminimal QPA plugin and using the -platform commandline switch to load it explicitly.

    Cheers,
    _

  6. #6
    Join Date
    Nov 2014
    Posts
    54
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11
    Thanks
    5

    Default Re: How to convert QString to QImage

    Hi anda_skoa,

    we are not using Qt-5,we are using Qt-4.7.4

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: How to convert QString to QImage

    I see.

    You'll have to check where the request for the framebuffer connection comes from, QImage quite certainly doesn't need it.

    Alternatively you could look into providing a virtual framebuffer that the application would then work with, or a virtual X server, e.g. Xvfb

    Cheers,
    _

  8. #8
    Join Date
    Nov 2014
    Posts
    54
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11
    Thanks
    5

    Default Re: How to convert QString to QImage

    Hi anda_skoa,

    we are getting problem with QPainter.
    Can you provide any link or documentation for Xvfb installation or configuration

Similar Threads

  1. Convert QVidoFrame to QPixMap / QImage is very slow
    By hasti in forum Qt Programming
    Replies: 4
    Last Post: 22nd September 2014, 17:25
  2. How to convert multi page Magick++ Image to QImage?
    By eadorean in forum Qt Programming
    Replies: 2
    Last Post: 9th September 2013, 19:28
  3. Replies: 3
    Last Post: 20th June 2013, 16:50
  4. How To Convert CGImageRef to QImage
    By nareshqt in forum Qt Programming
    Replies: 0
    Last Post: 23rd June 2008, 09:21
  5. Convert RAW 8 bit pixels into a QImage
    By danielperaza in forum Qt Programming
    Replies: 3
    Last Post: 10th March 2008, 15:53

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
  •  
Qt is a trademark of The Qt Company.