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 8584715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:50:13+00:00 2026-06-11T21:50:13+00:00

I’m trying to integrate a Qt library with an SDL application. I’d like to

  • 0

I’m trying to integrate a Qt library with an SDL application. I’d like to convert a QPixmap to an SDL_Surface, and then display that surface. How can I do this? I’ve not been able to find any good examples.

I’ve managed the following code so far:

Uint32 rmask = 0x000000ff;
Uint32 gmask = 0x0000ff00;
Uint32 bmask = 0x00ff0000;
Uint32 amask = 0xff000000;

SDL_FillRect(screen, NULL, SDL_MapRGBA(screen->format, 255, 255, 255, 255));

const QImage *qsurf = ...;

SDL_Surface *surf = SDL_CreateRGBSurfaceFrom((void*)qsurf->constBits(), qsurf->width(), qsurf->height(), 32, qsurf->width() * 4, rmask, gmask, bmask, amask);
SDL_BlitSurface(surf, NULL, screen, NULL);
SDL_FreeSurface(surf);
SDL_Flip(screen);

This works, but the only problem is that each time my QImage-based surface is painted, the underlying area is not cleared and the transparent parts “fade” into solid over the course of a few frames.

I do have SDL_FillRect which I would imagine clears the screen but it doesn’t seem to be doing so. screen is the primary SDL surface.

  • 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-06-11T21:50:14+00:00Added an answer on June 11, 2026 at 9:50 pm

    My original problem of overpainting was because my source image was actually not getting cleared properly. Oops. Once I fixed that, I simply had my masks wrong; not having it click in my mind how SDL was using these. The final, working code is as follows:

    Here’s the function to convert a QImage to an SDL_Surface:

    /*!
     * Converts a QImage to an SDL_Surface.
     * The source image is converted to ARGB32 format if it is not already.
     * The caller is responsible for deallocating the returned pointer.
     */
    SDL_Surface* QImage_toSDLSurface(const QImage &sourceImage)
    {
        // Ensure that the source image is in the correct pixel format
        QImage image = sourceImage;
        if (image.format() != QImage::Format_ARGB32)
            image = image.convertToFormat(QImage::Format_ARGB32);
    
        // QImage stores each pixel in ARGB format
        // Mask appropriately for the endianness
    #if SDL_BYTEORDER == SDL_BIG_ENDIAN
        Uint32 amask = 0x000000ff;
        Uint32 rmask = 0x0000ff00;
        Uint32 gmask = 0x00ff0000;
        Uint32 bmask = 0xff000000;
    #else
        Uint32 amask = 0xff000000;
        Uint32 rmask = 0x00ff0000;
        Uint32 gmask = 0x0000ff00;
        Uint32 bmask = 0x000000ff;
    #endif
    
        return SDL_CreateRGBSurfaceFrom((void*)image.constBits(),
            image.width(), image.height(), image.depth(), image.bytesPerLine(),
            rmask, gmask, bmask, amask);
    }
    

    And the core of my drawing function:

    // screen == SDL_GetVideoSurface()
    // finalComposite == my QImage that SDL will convert and display
    SDL_FillRect(screen, NULL, SDL_MapRGBA(screen->format, 255, 255, 255, 255));
    SDL_Surface *surf = QImage_toSDLSurface(finalComposite);
    SDL_BlitSurface(surf, NULL, screen, NULL);
    SDL_FreeSurface(surf);
    SDL_Flip(screen);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.