Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. (QDir , QFile !) How to change code source of My Qt Application frome another application ?
QtWS25 Last Chance

(QDir , QFile !) How to change code source of My Qt Application frome another application ?

Scheduled Pinned Locked Moved Solved General and Desktop
18 Posts 6 Posters 1.0k 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.
  • A Alex42
    8 Feb 2022, 07:22

    @SGaist , thanks for your response , unfortunately i haven't common part between different Applications ,

    the philosophy of the problem is , I have a big project, and I want every time a new developer develops a new widget, it will automatically add it to the big project without writing the same lines of code each time
    for this i want to develop a small application which can change the source code of the big project(.h and .cpp) and the new widget would be added automatically.
    for exemple now by using QDir and QFile , i can list the files, folder, directory of my (big Project .h and .cpp ) with this recursive directory method

    void MainWindow::RecursivlistDirectory(QString path)
    {
    
        QDir root(path);
        if(!root.exists())
        {
            qInfo() << "root Path not existe " ;
            return;
        }
    
        QFileInfoList MyFilelist = root.entryInfoList(QDir::Filter::NoDotAndDotDot | QDir::Filter::AllEntries);
    
        foreach(QFileInfo MyFile, MyFilelist)
        {
            int i =0;
    
            qInfo() << "N" << MyFile.fileName();
    
    
            QString T =".h,.cpp";
            MyFile.isDir() ? T = "Dir" : T = "File";
            qInfo() << "T" << T;
    
            if( MyFile.isDir())
            {
                i=i+1;
                qInfo() << "Yes Recursivity intel 0 file "<<i;
                RecursivlistDirectory(MyFile.absoluteFilePath());
            }
        }
    
    
    }
    

    And now I want every time I find the .h and .cpp files, I'll update them!
    unfortunately i don't know if is it possible ? and how ?
    thanks in advance for your advice and feedback .

    J Offline
    J Offline
    jsulm
    Lifetime Qt Champion
    wrote on 8 Feb 2022, 07:26 last edited by jsulm 2 Aug 2022, 07:27
    #4

    @Alex42 said in (QDir , QFile !) How to change code source of My Qt Application frome another application ?:

    unfortunately i haven't common part between different Application

    You have: " i created a widget on (Softadd) , and now i want to add this widget to the (Softvictim )".
    What you are trying to do with QFile/QDir makes absolutelly no sense!
    C++ is a compiled language, not an interpreted one! You can't add C++ source code somehow at runtime to your application and make it work.
    If you want to use a piece of code in more than one project then you need to put it into a library and use this library in these projects. This is what @SGaist suggested.

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Alex42
      wrote on 8 Feb 2022, 07:49 last edited by
      #5

      @jsulm
      " What you are trying to do with QFile/QDir makes absolutelly no sense!"
      why makes absolutely no sense !?
      As I have mentioned it well in my last comment
      QDir and QFile , here juste to list the files, folder, directory of my (big Project .h and .cpp ) and every time I find the .h and .cpp files, I'll update them!

      J J 2 Replies Last reply 8 Feb 2022, 07:58
      0
      • A Alex42
        8 Feb 2022, 07:49

        @jsulm
        " What you are trying to do with QFile/QDir makes absolutelly no sense!"
        why makes absolutely no sense !?
        As I have mentioned it well in my last comment
        QDir and QFile , here juste to list the files, folder, directory of my (big Project .h and .cpp ) and every time I find the .h and .cpp files, I'll update them!

        J Offline
        J Offline
        J.Hilk
        Moderators
        wrote on 8 Feb 2022, 07:58 last edited by
        #6

        @Alex42 I think I understand what you want o archive.

        I would suggest using a proper versioning tool, like git. Then you can add Softadd and softAttaq as submodules to Softvictim. Then you simply execute pull to update the submodules inside your main project.

        You can jigsaw your own system together via Qt, but why reinvent the wheel, again :D


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        1
        • A Alex42
          8 Feb 2022, 07:49

          @jsulm
          " What you are trying to do with QFile/QDir makes absolutelly no sense!"
          why makes absolutely no sense !?
          As I have mentioned it well in my last comment
          QDir and QFile , here juste to list the files, folder, directory of my (big Project .h and .cpp ) and every time I find the .h and .cpp files, I'll update them!

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 8 Feb 2022, 08:04 last edited by
          #7

          @Alex42 OK, sorry, I misunderstood what you are trying to achieve.
          Look at what @J-Hilk suggested.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Alex42
            wrote on 8 Feb 2022, 08:08 last edited by
            #8

            @J-Hilk
            it's seems very interesting , i don't know that existed other solutions like what you suggest me!
            can you give me more information for this solution or any link (exemple),
            thanks for your help

            J 1 Reply Last reply 8 Feb 2022, 08:11
            0
            • A Alex42
              8 Feb 2022, 08:08

              @J-Hilk
              it's seems very interesting , i don't know that existed other solutions like what you suggest me!
              can you give me more information for this solution or any link (exemple),
              thanks for your help

              J Offline
              J Offline
              J.Hilk
              Moderators
              wrote on 8 Feb 2022, 08:11 last edited by
              #9

              @Alex42 sure let me google that for you:

              https://git-scm.com
              https://git-scm.com/docs/gitsubmodules

              https://git-scm.com/videos
              https://git-scm.com/book/en/v2


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              1 Reply Last reply
              1
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 8 Feb 2022, 08:19 last edited by
                #10

                If I may, before starting to wildly create submodules within your different projects, you really should take the time to think about the architecture of them.

                You seem to have one main "project" that is composed of several applications i.e. "subprojects". If that's indeed the case, the architecture that would make most sense would be to use the SUBDIRS template since you are using qmake.

                As already suggested, create one library subproject that will contain the widgets that you want to reuse in your different applications. Then you can have one subproject per application that will use that library of common components. Doing so you would have your code neatly in one single place.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                1
                • A Offline
                  A Offline
                  Alex42
                  wrote on 8 Feb 2022, 08:33 last edited by
                  #11

                  @SGaist good analysis, thank you,
                  So, if I understand correctly , the answer to my question , it is not possible to change the source code of my qt Application from another application using QDir and QFile ?

                  J S 2 Replies Last reply 8 Feb 2022, 08:42
                  0
                  • A Alex42
                    8 Feb 2022, 08:33

                    @SGaist good analysis, thank you,
                    So, if I understand correctly , the answer to my question , it is not possible to change the source code of my qt Application from another application using QDir and QFile ?

                    J Offline
                    J Offline
                    JonB
                    wrote on 8 Feb 2022, 08:42 last edited by
                    #12

                    @Alex42 It is possible but totally inadvisable......

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      Alex42
                      wrote on 8 Feb 2022, 08:50 last edited by
                      #13

                      @SGaist The problem here is not a library , I know I can do it with a library, but as you see, I do not know how much widget and what kind of widget that We will add to my principale application in the future ,
                      for this , i want every time a new widget developed , will be added to the principal application Automatically, (by updating the .h and .cpp of the principal application)

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        Alex42
                        wrote on 8 Feb 2022, 09:06 last edited by
                        #14

                        @JonB what do you mean by "but totally inadvisable......"
                        according to you ? , I'm on the right track using qdir and qfile?

                        J 1 Reply Last reply 8 Feb 2022, 10:24
                        0
                        • A Alex42
                          8 Feb 2022, 08:33

                          @SGaist good analysis, thank you,
                          So, if I understand correctly , the answer to my question , it is not possible to change the source code of my qt Application from another application using QDir and QFile ?

                          S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 8 Feb 2022, 09:52 last edited by
                          #15

                          @Alex42 said in (QDir , QFile !) How to change code source of My Qt Application frome another application ?:

                          @SGaist good analysis, thank you,
                          So, if I understand correctly , the answer to my question , it is not possible to change the source code of my qt Application from another application using QDir and QFile ?

                          You are mixing project management and application code.

                          You can create a dedicated application that will copy the files around, but that's just maintenance hell in the making and completely counter intuitive.

                          @Alex42 said in (QDir , QFile !) How to change code source of My Qt Application frome another application ?:

                          @SGaist The problem here is not a library , I know I can do it with a library, but as you see, I do not know how much widget and what kind of widget that We will add to my principale application in the future ,
                          for this , i want every time a new widget developed , will be added to the principal application Automatically, (by updating the .h and .cpp of the principal application)

                          I do not see a problem with not knowing what you are going to add to your application at some point in time.
                          Automating the addition of a new widget to your application code does not make much sense. It should be a conscious decision recorded through your version control system. You may automate some of that stuff through your IDE, but trying to automagically add stuff is a bad idea. For example: why would you need to include that new widget in any of your headers ? Forward declaration will likely be the best practice to follow. Your main and secondary applications may change structurally so what was valid for a version will not be for another.

                          Too much automation is wrong, especially when it comes to structuring your code.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          2
                          • A Alex42
                            8 Feb 2022, 09:06

                            @JonB what do you mean by "but totally inadvisable......"
                            according to you ? , I'm on the right track using qdir and qfile?

                            J Offline
                            J Offline
                            JonB
                            wrote on 8 Feb 2022, 10:24 last edited by
                            #16

                            @Alex42 said in (QDir , QFile !) How to change code source of My Qt Application frome another application ?:

                            @JonB what do you mean by "but totally inadvisable......"
                            according to you ? , I'm on the right track using qdir and qfile?

                            I mean it is physically possible, which is what you asked, but you should not be doing it under any circumstances. As I and everybody have said. That should be 100% clear.

                            1 Reply Last reply
                            0
                            • M Offline
                              M Offline
                              mpergand
                              wrote on 8 Feb 2022, 11:49 last edited by mpergand 2 Aug 2022, 12:08
                              #17

                              i want every time a new widget developed , will be added to the principal application

                              It seems very close to what I am doing here:
                              Custom Widgets

                              This widgets are defined in a dedicated .pri module,
                              excerpts from UIWidget_v1.2.pri:

                              SourcePath = $$PWD/UIWidget/v1.2
                              
                              INCLUDEPATH +=  $$SourcePath
                              
                              HEADERS  += $$SourcePath/UIWidgetDefs.h \
                                          $$SourcePath/Knob.h \
                                          $$SourcePath/UIWContainer.h \
                                          $$SourcePath/KnobGroup.h
                              
                              SOURCES  += $$SourcePath/Knob.cpp \
                                          $$SourcePath/KnobGroup.cpp \
                                          $$SourcePath/UIWContainer.cpp
                              

                              As you can see there's some kind of versioning.

                              Each app that use these widgets add the .pri to their .pro:

                              # UIWidget
                              include( ../Qt5.12_Sources/UIWidget_v1.2.pri )
                              

                              Whenever a new widget is added to the UIWidget.pri, it is available to all apps that include that .pri.

                              1 Reply Last reply
                              0
                              • A Offline
                                A Offline
                                Alex42
                                wrote on 8 Feb 2022, 16:53 last edited by
                                #18

                                @mpergand thank you for your suggestion
                                finally i managed to do what I wanted with Qdir and Qfile (changing the source code ) but as discussed previously it's not practical
                                Your suggestion is not Bad, but as I mentioned it above My problem is different ,
                                I'll think about the team's proposals!
                                thanks anyways

                                1 Reply Last reply
                                0

                                13/18

                                8 Feb 2022, 08:50

                                • Login

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