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

  • Home
  • SEARCH
  • 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 4255506
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:13:42+00:00 2026-05-21T05:13:42+00:00

I am new to programming. I am creating a small word jumble game to

  • 0

I am new to programming. I am creating a small word jumble game to practice qt programming. In this application I am creating a text file (score.txt) to keep score of player. I have done this by:

    QFile scoreFile("score.txt");
    if (QFile::exists("score.txt"))
    {
        scoreFile.open(QIODevice::ReadWrite | QIODevice::Text)
        // and update the score.
    }
    else
    {
        scoreFile.open(QIODevice::ReadWrite | QIODevice::Text);//create score file
        //and write the score to it.
    }

this code is working good here. Now I am using CMake to build and install generated binary (I am working on Ubuntu) using this code:

#set project name, version and build code here.

install(TARGETS wordJumbleGame DESTINATION bin)

I build project in /home/myname/project/build/

My source code is in /home/myname/project/src/

CMakeLists.txt is in /home/myname/project/CMakeLists.txt

I installed program using make install.
Till here all things working fine. But now problem is that when I run this program (I run it from terminal giving command wordJumbleGame) It creates score.txt in /home/myname/project/build directory. It is not being created in installation dir bin.

So please help me out, what am I doing wrong. And please also tell me how do I make my program to appear in application->game lists so I can run it from there not from command prompt.

  • 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-21T05:13:42+00:00Added an answer on May 21, 2026 at 5:13 am

    Unless you prefix it with a slash (on unix) or a drive path (Windows), QFile’s constructor parameter is a relative path – relative to the current working directory. score.txt is created in the build/ directory because that’s probably where you’re executing the binary from.

    You can’t store score.txt in the /usr/bin directory because, typically, you can’t write there without root privileges.

    What you want to do is get a path to some directory where you can store your score.txt file. To do that, you can use the QDesktopServices class. That will give you directory information on a per-user basis. Here’s an example:

    #include <QDesktopServices>
    
    // this would go in main(), probably
    QCoreApplication::setApplicationName( "word jumble game" );
    
    // now when you want to read/write the scores file:
    QString dataPath = QDesktopService::storageLocation( QDesktopService::DataLocation );
    QFile scoreFile( dataPath + "score.txt" );
    
    // on my system, this produces: "/home/adam/.local/share/data/word jumble game/score.txt"
    // it will produce something similar for Windows and Mac too
    

    You should set your appication name via QCoreApplication::setApplicationName before getting path information to keep the user data directory nice and organised.

    As for getting your application in the games list, you’ll need to create a menu entry that follows the freedesktop.org spec. I can’t help you more with that, but this is a good starting point. Somebody else might have more info for you.

    You need to create a .desktop entry file and install it using xdg-desktop-menu install. Here are two resources for you: freedesktop.org menu spec and adding .desktop files using CMake

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

Sidebar

Related Questions

I'm pretty new to programming in general and I'm creating a small game for
I'm fairly new at programming, but I've wondered how shell text editors such as
I am fairly new to programming and while doing a lot of reading this
i been thinking of a new programming language. Before trying to implement it i
Im new to programming and I dont know very much about but I'm making
I am new to programming, and am wondering if there is a correct way
I'm quite new to programming, and I was wondering if there is a good
We have 2 new GIS programmer/analyst in our department (new to programming and ArcObjects)
I'm new to Flex, although not new to programming. I want to write a
New to Linux programming in general. I am trying to communicate with a kernel

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.