Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How can I save a file and open again?



  • Hi all,
    I have prepared a project using the blocks and connected them with each other.(in the screen shot) How can I save this file to a directory to be able to open again then?

    0_1550144721587_Screenshot from 2019-02-14 14-41-24.png



  • hi @Yunus
    you can use Settings
    or store it as JSON



  • This post is deleted!


  • @LeLev Thank you! I m able to save the blocks position now using settings. But how can I save my canvas lines. Here is the code How I created canvas lines.

    Canvas {
                id: spline_canvas
                width: node_edit.width
                height: node_edit.height
                onPaint:{
                    function do_spline(x1, y1, x2, y2, context) {
    
                        context.moveTo(x1, y1);
                        if(x1>x2) {
                            context.bezierCurveTo((x1-x2)+x1,y1,x2-(x1-x2),y2, x2, y2);
                        } else {
                            context.bezierCurveTo((x1+x2)/2,y1,(x1+x2)/2, y2, x2, y2);
                        }
                    }
    
                    var ctx = spline_canvas.getContext("2d");
                    ctx.clearRect(0, 0, spline_canvas.width, spline_canvas.height);
                    ctx.strokeStyle = Qt.rgba(0, 0, 0, 1);
                    ctx.lineWidth = 1;
                    ctx.beginPath();
                    // num1 -> sum1
                    do_spline(num1_out1.x+num1.x+16, num1.y+num1_out1.y+34, node.x+5, node.y+8, ctx);
    }
    


  • @Yunus
    Instead of saving the lines maybe you can draw them once you positioned the blocks



  • @Yunus

    Instead of saving the lines maybe you can draw them once you positioned the blocks

    I agree with @LeLev, after having positioning the nodes then you draw the lines for the nodes that are connected. Obviously you need to store what nodes are connected as well



  • I have used quite a few programs that draw lines between objects and sometimes the lines themselves have labels and parameters after you drag and adjust them. If that is a need then having lines as objects themselves would make sense.



  • @fcarney Ok, good point.

    So it looks like saving nodes (wtih label & position) and connections (with label and what nodes they connect to/from) will do the trick. Then it's up to the drawing phase to do all the bells and whistles



  • @Pablo-J-Rogina @LeLev @fcarney thank you all. I will try what you said. But my problem is here now.
    For example I m writing the below code at the begining of my program. And It saves the last points of blocks or window. It is okey but when I opened the program again, their position is not at the begining position and it is also okey. The point is I dont want the program call the last locations automatically, I want it to control with a button. Or how can I reach saved position after closing the program.

    Settings {
    id: mainSettings
    property alias x: block.x
    property alias y: block.y
    property alias width: block.width
    property alias height: block.height
    }



  • @Yunus one other solution is to export needed informatons to a file json or xml for example


Log in to reply