(Solved) Removing square (objects) from my GUI

  • Hi everyone. I currently have a .txt file which has a list of (x,y) coordinates. I read this and create square objects and display to the screen. I have a for loop that loops through all the x,y coordinates in the .txt file and generates the objects such as:

    @ for (unsigned int i = 0; i < coordinatesTextFile.size(); i++){
    //convert local coordinates to GUI coordinates

        DisplayObjects *obstacle = new DisplayObjects(((coordinatesTextFile[i][0]-1)*(screenLength/xSquareSize)),((coordinatesTextFile[i][1]-1)*(screenWidth/ySquareSize)-1));

    I want to be able to delete/add old/new coordinates from my .txt file and have the square objects show the result dynamically. Currently I have to close the GUI and re-run the program.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    One way to do it:

    • QFileSystemWatcher to get notifications when the file is modified.
    • Re-read the file
    • Update your coordinate list
    • Update your scene

    Hope it helps

  • Brilliant, thank you SGaist!

  • Lifetime Qt Champion

    You're welcome !

    If this answers your question, please update the thread title prepending solved so other forum users may know a solution has been found :)

  • Hi SGaist, just to check, I edited the title to include (Solved). Is this what you meant?

  • Lifetime Qt Champion

    Exactly yes :)

Log in to reply