Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How can I save a file and open again?
QtWS25 Last Chance

How can I save a file and open again?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
10 Posts 4 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • YunusY Offline
    YunusY Offline
    Yunus
    wrote on last edited by
    #1

    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

    ODБOïO 1 Reply Last reply
    0
    • YunusY Yunus

      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

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

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

      1 Reply Last reply
      1
      • YunusY Offline
        YunusY Offline
        Yunus
        wrote on last edited by Yunus
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • YunusY Offline
          YunusY Offline
          Yunus
          wrote on last edited by
          #4

          @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);
          }
          
          ODБOïO Pablo J. RoginaP 2 Replies Last reply
          0
          • YunusY Yunus

            @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);
            }
            
            ODБOïO Offline
            ODБOïO Offline
            ODБOï
            wrote on last edited by
            #5

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

            1 Reply Last reply
            1
            • YunusY Yunus

              @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);
              }
              
              Pablo J. RoginaP Offline
              Pablo J. RoginaP Offline
              Pablo J. Rogina
              wrote on last edited by
              #6

              @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

              Upvote the answer(s) that helped you solve the issue
              Use "Topic Tools" button to mark your post as Solved
              Add screenshots via postimage.org
              Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              1
              • fcarneyF Offline
                fcarneyF Offline
                fcarney
                wrote on last edited by
                #7

                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.

                C++ is a perfectly valid school of magic.

                Pablo J. RoginaP 1 Reply Last reply
                1
                • fcarneyF fcarney

                  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.

                  Pablo J. RoginaP Offline
                  Pablo J. RoginaP Offline
                  Pablo J. Rogina
                  wrote on last edited by Pablo J. Rogina
                  #8

                  @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

                  Upvote the answer(s) that helped you solve the issue
                  Use "Topic Tools" button to mark your post as Solved
                  Add screenshots via postimage.org
                  Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                  1 Reply Last reply
                  1
                  • YunusY Offline
                    YunusY Offline
                    Yunus
                    wrote on last edited by Yunus
                    #9

                    @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
                    }

                    ODБOïO 1 Reply Last reply
                    0
                    • YunusY Yunus

                      @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
                      }

                      ODБOïO Offline
                      ODБOïO Offline
                      ODБOï
                      wrote on last edited by
                      #10

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

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved