(QDir , QFile !) How to change code source of My Qt Application frome another application ?
-
Hello,
i want to change the code source of my project (Qt Application) Automatically frome another application ,
for exemple here i have 3 applications, SoftAttaq, SoftVictim and Softadd ; i created a widget on (Softadd) , and now i want to add this widget to the (Softvictim ) frome (softAttaq)
My questions :
1: is it possible to do what i'm trying to do ;
2: for the moment by using QDir and QFile , i can list the files, folder, directory of my (softVictim ) , but i don't now how to change the code source and add my widget Automatically
attached the structures of my 3 software

any advice , feedback , you are welcome
thanks in advance; -
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.
-
@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 methodvoid 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 . -
@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 methodvoid 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 .@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. -
@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! -
@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!@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
-
@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-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@Alex42 sure let me google that for you:
-
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.
-
@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 ? -
@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) -
@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 ?@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.
-
@JonB what do you mean by "but totally inadvisable......"
according to you ? , I'm on the right track using qdir and qfile?@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.
-
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 WidgetsThis 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.
-
@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