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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:35:41+00:00 2026-05-27T06:35:41+00:00

Every time I run my project in Qt Creator, it spins up another instance

  • 0

Every time I run my project in Qt Creator, it spins up another instance of my app. I have to manually quit the app or else my Dock gets full pretty fast. What a pain. Is there a way around this? It would make a lot more sense if when I run the app again, I could just terminate the already running version. Can this be done?

  • 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-27T06:35:42+00:00Added an answer on May 27, 2026 at 6:35 am

    you can use shared memory to solve your problem. I have used this approach to not start another instance of my program while there is already a running instance. Actually I have implemented this to achieve so called single instance application.

    However your case is a bit different from mine, you need to somehow send a signal from 2nd application to the first one to make it close. I think you can achieve this behaviour still using QSharedMemory.

    What I’ve done to achive single instance app is to create a shared memory with a universally unique id(UUID) as key and every time my program starts put a lock on it, so if it is already locked my program understands there is already a running instance and closes automatically.

    You need to improve this implementation to adapt your requirement. In theory what you need to do is to put a function pointer(or a qt signal) to the shared memory and when another instance come up make your (second) instance fire that function which forces to exit the first instance. Unfortunately I don’t know how to implement this but I hope this would give you an opinion…

    The flow should be somewhat like follows:

    IN MAIN
       check if shared memory in use
          if yes
             fire the exit function via shared memory to close 1st app
          if no
             put the function pointer which will close the app when another instance come up
    
        do stuff
    

    To give you a slight hint, my code for single instance is like follows

    QSharedMemory shared(AppConstants::UUID); //Global variable
    
    int main(){
    // Ensure single instanse of App
    if( !shared.create( 512, QSharedMemory::ReadWrite) )
    {
        // QMessageBox msgBox;
        QMessageBox::critical(0, QObject::tr("App is already running!"), QObject::tr("App is already running!"), QMessageBox::Ok, QMessageBox::Ok);
        qCritical() << "Cevirgec is already running!";
    
        exit(0);
    }
    else {
        qDebug() << "App staring...";
    }
    }
    

    good luck and don’t forget to share your solution here 😉

    EDIT:

    If putting a function pointer or Qt signal and then fire it is impossible(I hope not) you can put a variable to shared memory to lets say hold the number of running instances and in your app periodically(in a thread) check it and if it is greater than 1 close the application.

    Watch out for race conditions here! You can avoid race conditions by putting a pair of a random number generated by each instance and start time. so before closing, your app ensures that it is the elder one. Ex: QPair<int, QDateTime>

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

Sidebar

Related Questions

I have a file that suffers modification every time I run my project. Thus,
I have this warning every time I run my CGI-script (output is rendered by
If I have an immutable string is the hashing algorithm run every time I
I have a Visual Studio 2005 solution. Every time I try to run the
The app will run fine, then crash - literally every other time. It seems
I would like to run a code generator every time my project is built
Every time I run my Android project from Eclipse, it starts a new Android
My app generates 3 files every time the user saves a project. I would
I'm getting segfaults when I run my project. Every time I run the program
Literally every second time I run a big ugly web site project, I get

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.