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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:36:40+00:00 2026-06-11T02:36:40+00:00

In my Qt application I am saving some data when application is being closed.

  • 0

In my Qt application I am saving some data when application is being closed. Saving data is performed in the closeEvent(QCloseEvent*) method. I wanted to change the cursor before the saving data and restore it back after saving.

From what I have read over the Internet the setCursor( const QCursor& ) doesn’t work globally, but only in the scope of some specified widget. Therefore I tried to use SetCursor( HCURSOR ) from WinAPI.

The code looks like this:

void mainWin::closeEvent( QCloseEvent* e ) {
    SetCursor( LoadCursor( GetModuleHandle( NULL ), ( LPCWSTR )IDC_WAIT ) );
    saveData();
    SetCursor( LoadCursor( GetModuleHandle( NULL ), ( LPCWSTR )IDC_ARROW ) );
    e->accept();
}

However, the first SetCursor() method just hides the cursor for the time when the data is saving instead of changing it to some kind of hourglass. Why?

  • 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-11T02:36:42+00:00Added an answer on June 11, 2026 at 2:36 am

    You should use QApplication::setOverrideCursor, it will change your cursor for your entire application.

    QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
    saveData();
    QApplication::restoreOverrideCursor();
    

    You can of course provide your own pixmap when you create your cursor.
    One other interesting thing that you can do is creating a RAII class to handle a custom cursor. You call setOverrideCursor in the constructor and the restoreOverrideCursor in the destructor. Doing so is quite handy when you have many places where you want to change the cursor and automatically restore it at the end of the scope. One other advantage is that if your saveData method throws, your cursor is reset anyway, which is quite nice.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a Windows Forms application I'm saving some data to an Excel file. Until
When my activity is being closed, I serialize the application state data to file
My android application is saving some stats to internal storage. Each file name is
I'm developing a desktop application with .NET. I'd like to save some data into
This somewhat follows on from the question Saving application data to the ipad/iphone Really
For a Windows 8 Application in C/XAML I have to store some data to
Are there any state saving method that would allow JSF application to intially save
I have been trying to go back to an activity after saving some data.
I'm developing a corodva (phonegap) application and I'm saving some downloaded files to the
I have an Web-application in which I capture Image using EdgeCamShots Sample Application Saving

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.