.ico/cur plugin

  • Hello,
    I need help, with my faculty project which is about to make plugin that will support ico/cur format (can read and save these types of formats, in C++). Unfortunality, this is the first time that facing the experience with qt creator and plugins, so I don't really know how to do my project. Did someone do something similar with my topic? I desparately need help:)

  • Have a look at this introduction, it may help:


  • thanx for the doc, it helped me a bit, but I have some missunderstandings yet.

    what does mean this line of code:

    @bool IcoHandler::canRead(QIODevice *device)
    return device->peek(4) == "\xCA\xFE\x12\x34";

  • that is for ARGB format, and which magic number will be for ICO format?

  • Moderators

    Google for the ico format specification. That will have all the details you need to read and write the format.

  • I found that ico hasnt magic number. So, will it just be:
    @return device;@

    I know that these are tirvial questions, but I really never worked with Qt, esspecialy plugins and image formats.

  • Qt framework will call this function for every *.ico file, so if you are sure that every *.ico file can be read (i.e. doesn't have magic number), than just
    return true;

  • Another question is: can I use this function also in the case of .ico format (it is previously writen for raw format):

    @bool IcoHandler::write(const QImage &image)
    QImage result = image.convertToFormat(QImage::Format_RGB32);
    QDataStream output(device());
    quint32 width = result.width();
    quint32 height = result.height();
    output << width << height;
    for (quint32 y = 0; y < height; ++y) {
    QRgb *scanLine = (QRgb *)result.scanLine(y);
    for (quint32 x = 0; x < width; ++x)
    output << scanLine[x];
    if ((width!=48 && height!=48) || (width!=32 && height!=32) || (width!=24 && height!=24) || (width!=16 && height!=16))
    return false;

    return output.status() == QDataStream::Ok;


  • See "ico/cur file format":http://en.wikipedia.org/wiki/ICO_(file_format)#Outline

    Edit: correct link is http://en.wikipedia.org/wiki/ICO_(file_format)#Outline
    Maybe is a bug if link contains '#' character

  • yes, I saw that and many other documents related to these formats, but unfortunately, I don't know how to implement.

  • Moderators

    Faculties tend to have teachers which -- based on my experience -- are happy to help when asked specific questions.

    How about taking an .ico, converting it to e.g. png using any graphics application. Then you can have Qt read the png and feed that into your write method. If the output is identical to the original .ico file, then you are done. For the read method you can do something similar: You read the orginal file, compare that to the png.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.