Results 1 to 17 of 17

Thread: QPixmap and QVariant

  1. #1
    Join Date
    Sep 2007
    Location
    Germany
    Posts
    35
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy QPixmap and QVariant

    Hi everybody,

    I am working on a software that is using an active x control. The active x has function that return a bitmap as QVariant, tha Qvariant Type is QvariantList, and the item type inside the list are reconigzes as int.

    The Function is suppose to return this information wrap in a variant:

    • BitmapInfoHeader: (WINDOWS BITMAPINFOHEADER sturct);
    • Palette 256 element arrayof Windows PALETTEENTRY;
    • Bits Two-Dimensional array of byte. the size of the array is specified in the bitmapInfoHeader.bSizeImage


    Well this is what i am doing:

    Qt Code:
    1. QVariantList list = ActiveXObject->Bitmap().toList();
    2. uchar unChList[list.size()];
    3. for (qint32 i = 0; i < list.size(); i++)
    4. {
    5. unChList[i] = a.at(i).toUInt();
    6. }
    7. QPixmap pixBeam;
    8. pixBeam.loadFromData(unChList, list.size());
    9. QString name = "File.pdf";
    10. QPrinter printer;
    11. printer.setOutputFormat(QPrinter::PdfFormat);
    12. printer.setOutputFileName(name);
    13. printer.setPageSize(QPrinter::A4);
    14. printer.setPageMargins(25, 10, 20, 10, QPrinter::Millimeter);
    15. printer.setFullPage(false);
    16.  
    17. QPainter painter;
    18. if (!painter.begin(&printer))
    19. {
    20. qWarning("failed to open file, is it writable?");
    21. return;
    22. }
    23. painter.setWindow(0, 0, 1650, 2750);
    24.  
    25. QPen pen;
    26. pen.setBrush(QBrush(Qt::black, Qt::SolidPattern));
    27. painter.setPen(pen);
    28.  
    29. /*********
    30.  *here i draw also some rects and text
    31. *********/
    32.  
    33. painter.drawPixmap(QRect(0, 100, 1650, 1200), pixBeam, pixBeam.rect());
    34.  
    35. /*********
    36.  *here i draw also some rects and text
    37. *********/
    38. painter.end();
    To copy to clipboard, switch view to plain text mode 

    The text and and squares and lines are there but the bitmap is not.
    How shall i conver this? i calling "fromData" function in a incorrect way?

    Thanks for the help in Advance

    PS: I have run with the printing of the value they have data inside.
    CAFU......

  2. #2
    Join Date
    Dec 2008
    Location
    TaganrogNativelandChehov,Russia
    Posts
    64
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPixmap and QVariant

    east or west home is best

  3. #3
    Join Date
    Sep 2007
    Location
    Germany
    Posts
    35
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Arrow Re: QPixmap and QVariant

    I think this is the function that i am using but i am not checking the return value,

    I will check and let you know
    Last edited by cafu; 23rd October 2009 at 10:12.
    CAFU......

  4. #4
    Join Date
    Sep 2007
    Location
    Germany
    Posts
    35
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPixmap and QVariant, Please Help!!!!!!

    The function returns false

    Some one can give a hint what to do...
    Last edited by cafu; 23rd October 2009 at 10:59.
    CAFU......

  5. #5
    Join Date
    Dec 2008
    Location
    TaganrogNativelandChehov,Russia
    Posts
    64
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPixmap and QVariant

    and why do you not use foramat argument ?
    "JPG"
    "PNG"
    etc...
    east or west home is best

  6. #6
    Join Date
    Sep 2007
    Location
    Germany
    Posts
    35
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPixmap and QVariant

    i am trying know with the argument and see?

    the things is to make a testi have to run it for around 15 min to wait for the active x to create the bitmap.
    CAFU......

  7. #7
    Join Date
    Sep 2007
    Location
    Germany
    Posts
    35
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: QPixmap and QVariant

    But do i need to send header and the palette or just the bits..?

    please help!!!!!!!!!!!!!!!!


    Last edited by cafu; 23rd October 2009 at 11:55.
    CAFU......

  8. #8
    Join Date
    Sep 2007
    Location
    Germany
    Posts
    35
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPixmap and QVariant

    So have someone Idea how to work aroud this problem, thanks
    CAFU......

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPixmap and QVariant

    Qt Code:
    1. QVariantList list = ActiveXObject->Bitmap().toList();
    To copy to clipboard, switch view to plain text mode 
    What is this supposed to do? What is the variable "a"? What does it contain?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Sep 2007
    Location
    Germany
    Posts
    35
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPixmap and QVariant

    Sorry it was a typo it should be "list" which contains the bitmap.

    Qt Code:
    1. QVariantList list = ActiveXObject->Bitmap().toList();
    2. uchar unChList[list.size()];
    3. for (qint32 i = 0; i < list.size(); i++)
    4. {
    5. unChList[i] = list.at(i).toUInt();
    6. }
    7. QPixmap pixBeam;
    8. pixBeam.loadFromData(unChList, list.size());
    9. QString name = "File.pdf";
    10. QPrinter printer;
    11. printer.setOutputFormat(QPrinter::PdfFormat);
    12. printer.setOutputFileName(name);
    13. printer.setPageSize(QPrinter::A4);
    14. printer.setPageMargins(25, 10, 20, 10, QPrinter::Millimeter);
    15. printer.setFullPage(false);
    16.  
    17. QPainter painter;
    18. if (!painter.begin(&printer))
    19. {
    20. qWarning("failed to open file, is it writable?");
    21. return;
    22. }
    23. painter.setWindow(0, 0, 1650, 2750);
    24.  
    25. QPen pen;
    26. pen.setBrush(QBrush(Qt::black, Qt::SolidPattern));
    27. painter.setPen(pen);
    28.  
    29. /*********
    30.  *here i draw also some rects and text
    31. *********/
    32.  
    33. painter.drawPixmap(QRect(0, 100, 1650, 1200), pixBeam, pixBeam.rect());
    34.  
    35. /*********
    36.  *here i draw also some rects and text
    37. *********/
    38. painter.end();
    To copy to clipboard, switch view to plain text mode 
    CAFU......

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPixmap and QVariant

    Are you sure this conversion is valid? What does ActiveXObject->Bitmap() return? Are you sure it is QVariantList compatible? What happens if you use this instead?
    Qt Code:
    1. QByteArray ba = ActiveXObject->Bitmap().toByteArray();
    2. QPixmap pixmap(ba.constData());
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12
    Join Date
    Sep 2007
    Location
    Germany
    Posts
    35
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPixmap and QVariant

    The array is empty
    CAFU......

  13. #13
    Join Date
    Sep 2007
    Location
    Germany
    Posts
    35
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPixmap and QVariant

    and in when i called the function QVariant::typeName, it return QVariantList.


    But i will try again and i will let you know, do i have to send everthing with the headers and so on?
    Last edited by cafu; 27th October 2009 at 11:12.
    CAFU......

  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPixmap and QVariant

    I don't want your code, I won't be able to run it anyway as I'm using Linux. Just tell me what ActiveXObject->Bitmap() is meant to return. Also what is the size of the variant list?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #15
    Join Date
    Sep 2007
    Location
    Germany
    Posts
    35
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPixmap and QVariant

    Sorry for the missunderstood, but this is the information that i have:

    The Function is suppose to return this information wrap in a variant:

    * BitmapInfoHeader: (WINDOWS BITMAPINFOHEADER sturct);
    * Palette 256 element array of Windows PALETTEENTRY;
    * Bits Two-Dimensional array of byte. the size of the array is specified in the bitmapInfoHeader.bSizeImage

    This activeX is meant to work with labview or visual basic, but i have used the aciveQt example of qutlook to be able to use this with QT.
    CAFU......

  16. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPixmap and QVariant

    So why would you expect QPixmap to be able to load that directly?

    Qt Code:
    1. QVariantList vlist = ActiveXObject->Bitmap().toList();
    2. BITMAPINFOHEADER header = yourConvertFunc1(vlist.at(0));
    3. // here you have to convert PALETTEENTRY to QRgb
    4. QVector<QRgb> colortable = yourConvertFunc2(vlist.at(1));
    5. int hei = header.???;
    6. int wid = header.???;
    7. const char **rawData = yourConvertFunc3(vlist.at(2));
    8. for(int i=0;i<hei;++i){
    9. data.append(rawData[i], wid);
    10. }
    11. QImage image(wid, hei, QImage::Format_Indexed8); // or whatever else format this is
    12. memcpy(image.bits(), data.constData(), data.size()); // alternatively you can copy line by line instead of using an intermediate byte array
    13. image.setColorTable(colortable); // if needed
    14. QPixmap px = QPixmap::fromImage(image);
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  17. #17
    Join Date
    Sep 2007
    Location
    Germany
    Posts
    35
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPixmap and QVariant

    I am sorry if perhaps the question or the problem is not the adequate for the forum.

    But i am here trying to find a solution to a problem that i have not been able to solve on my own. I am no comming here to post after the first try. i post when i think that maybe someone can help me or has face before the problem, and has idea of this.

    About the load directly, well from the documentation is no clear("for me") what it should be send in the data. And I do not know if the header of the bitmap is need it.

    The aproach that you said is no working cuase the size of the variantList is a lot bigger than that. I tryed something similar a first. then i tryed this one, trying to conpy the memory values into the variables.

    Qt Code:
    1. QVariantList list = M2XObject->BeamBitmap().toList();
    2. BITMAPINFOHEADER header;
    3. PALETTEENTRY palette;
    4. uchar chHeader[sizeof(BITMAPINFOHEADER)];
    5. uchar chPalette[sizeof(PALETTEENTRY)];
    6. qint32 i = 0;
    7. for (quint32 k = 0; k < sizeof(BITMAPINFOHEADER); k++)
    8. {
    9. chHeader[k] = list.at(i).toInt();
    10. i++;
    11. }
    12. mencpy(header,chHeader,sizeof(BITMAPINFOHEADER));
    13. for (quint32 k = 0; k < sizeof(PALETTEENTRY); k++)
    14. {
    15. chPalette[k] = list.at(i).toInt();
    16. i++;
    17. }
    18. quint32 bitsSize=a.size()-sizeof(PALETTEENTRY)-sizeof(BITMAPINFOHEADER);
    19. uchar chBits[si];
    20. for (quint32 k = 0; k < bitsSize; k++)
    21. {
    22. chBits[k] = list.at(i).toInt();
    23. i++;
    24. }
    25. if (!pixBeam.loadFromData(chBits, bitsSize, "BMP"))
    26. {
    27. qWarning("loadFromData false");
    28. }
    To copy to clipboard, switch view to plain text mode 

    I will try to make a merge betwen the code you offer me and the one before, and i hope i will work as i need.

    Thanks, and i will let know if this work....
    Last edited by cafu; 27th October 2009 at 13:29.
    CAFU......

Similar Threads

  1. do we can't compare QIcon or QPixmap????
    By sudheer in forum Qt Programming
    Replies: 2
    Last Post: 13th May 2008, 14:53
  2. Use QVariant with custon data types
    By mcosta in forum Qt Programming
    Replies: 4
    Last Post: 11th January 2006, 14:55

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.