Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 521459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:15:09+00:00 2026-05-13T08:15:09+00:00

I have a char* data , where every char represents red/green/blue/alpha value of a

  • 0

I have a char* data, where every char represents red/green/blue/alpha value of a pixel.

So, the first four numbers are red, green, blue and alpha value of the first pixel, the next four are R, G, B, A value of the pixel on the right and so on.

It represents a picture (with previously known width and height).

Now, I want to somehow take this array and display it on Qt window. How to do it?

I know I should somehow use QPixmap and/or QImage, but I cannot find anything helpful in the documentation.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T08:15:10+00:00Added an answer on May 13, 2026 at 8:15 am

    QImage is designed for access to the various pixels (among other things), so you could do something like this:

    QImage DataToQImage( int width, int height, int length, char *data )
    {
        QImage image( width, height, QImage::Format_ARGB32 );
        assert( length % 4 == 0 );
        for ( int i = 0; i < length / 4; ++i )
        {
            int index = i * 4;
            QRgb argb = qRgba( data[index + 1], //red
                               data[index + 2], //green
                               data[index + 3], //blue
                               data[index] );   //alpha
            image.setPixel( i, argb );
        }
        return image;
    }
    

    Based on coming across another constructor, you might also be able to do this:

    QImage DataToQImage( int width, int height, int length, const uchar *data )
    {
        int bytes_per_line = width * 4;
        QImage image( data, width, height, bytes_per_line, 
                         QImage::Format_ARGB32 );
        // data is required to be valid throughout the lifetime of the image so 
        // constructed, and QImages use shared data to make copying quick.  I 
        // don't know how those two features interact, so here I chose to force a 
        // copy of the image.  It could be that the shared data would make a copy
        // also, but due to the shared data, we don't really lose anything by 
        // forcing it.
        return image.copy();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have taken char data into database into array. now i want to convert
I have a struct struct Packet { int senderId; int sequenceNumber; char data[MaxDataSize]; char*
I have an char* array of binary data. It is binary media-stream encoded with
I have two columns. ColA and ColB contains char(10) with data 20090520 and 20090521.
I have an std::vector<unsigned char> with binary data in. I just would like to
I have a vector<set<char> > data structure (transactions database) and I want to know
I have a view that receives new data from a secondary thread. Every time
I have this query that runs fine: SELECT Value FROM data WHERE MetaDataID =
I have a class that represents some file data. The file contains some headers.
We have one of those weird cryptic data corruption bugs that pops up every

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.