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 ?
Forum Updated to NodeBB v4.3 + New Features

(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.1k Views 2 Watching
  • 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    If you have common parts between different applications, the usual way to share them is to put them in a library and use that library with your various apps.

    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 Offline
      A Offline
      Alex42
      wrote on last edited by
      #3

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

      jsulmJ 1 Reply Last reply
      0
      • A Alex42

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

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by jsulm
        #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 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.HilkJ jsulmJ 2 Replies Last reply
          0
          • A Alex42

            @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.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on 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

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

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on 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 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.HilkJ 1 Reply Last reply
                0
                • A Alex42

                  @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.HilkJ Offline
                  J.HilkJ Offline
                  J.Hilk
                  Moderators
                  wrote on 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
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 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 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 ?

                      JonBJ SGaistS 2 Replies Last reply
                      0
                      • A Alex42

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

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by
                        #12

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

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          Alex42
                          wrote on 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 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?

                            JonBJ 1 Reply Last reply
                            0
                            • A Alex42

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

                              SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on 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

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

                                JonBJ Offline
                                JonBJ Offline
                                JonB
                                wrote on 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 last edited by mpergand
                                  #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 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

                                    • Login

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