Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Line Count in my Qt Project.

    General and Desktop
    10
    25
    12176
    Loading More Posts
    • 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.
    • Pradeep P N
      Pradeep P N last edited by

      Hi All,

      Is there any way to find out the total number lines count in my Qt Project.

      Thank You.

      Pradeep Nimbalkar.
      Upvote the answer(s) that helped you to solve the issue...
      Keep code clean.

      jsulm 1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        Hi
        You mean lines in all cpp and h files?

        I dont think Creator can show you.

        1 Reply Last reply Reply Quote 0
        • E
          Eddy last edited by

          this plugin looks promising

          Qt Certified Specialist
          www.edalsolutions.be

          mrjj Pradeep P N 2 Replies Last reply Reply Quote 5
          • mrjj
            mrjj Lifetime Qt Champion @Eddy last edited by

            @Eddy
            Nice find :)

            E 1 Reply Last reply Reply Quote 2
            • E
              Eddy @mrjj last edited by

              @mrjj said in Line Count in my Qt Project.:

              @Eddy
              Nice find :)

              I may have no glasses, but I can google ;-)

              Qt Certified Specialist
              www.edalsolutions.be

              mrjj 1 Reply Last reply Reply Quote 3
              • mrjj
                mrjj Lifetime Qt Champion @Eddy last edited by

                @Eddy
                Its also very good example of Creator plugin \o/

                1 Reply Last reply Reply Quote 2
                • jsulm
                  jsulm Lifetime Qt Champion @Pradeep P N last edited by

                  @Pradeep-P-N There is well known command line tool for that: sloccount

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

                  Pradeep P N 1 Reply Last reply Reply Quote 6
                  • Pradeep P N
                    Pradeep P N @Eddy last edited by

                    Hi @Eddy i did try it but i couldn't get the solution.
                    Hi @mrjj Yes i want to count all the lines in CPP and H and also in my QML files

                    Pradeep Nimbalkar.
                    Upvote the answer(s) that helped you to solve the issue...
                    Keep code clean.

                    1 Reply Last reply Reply Quote 1
                    • Pradeep P N
                      Pradeep P N @jsulm last edited by Pradeep P N

                      @jsulm Can you please give me more details on sloccount and how can i use it with Qt

                      Pradeep Nimbalkar.
                      Upvote the answer(s) that helped you to solve the issue...
                      Keep code clean.

                      jsulm mrjj 2 Replies Last reply Reply Quote 0
                      • jsulm
                        jsulm Lifetime Qt Champion @Pradeep P N last edited by

                        @Pradeep-P-N Why not just use Google?
                        Then you will find https://www.dwheeler.com/sloccount/
                        "how can i use it with Qt" - you don't use it with Qt (as Qt is not a programming language), you use it with your C++ source code. It does not support QML though.

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

                        1 Reply Last reply Reply Quote 1
                        • J.Hilk
                          J.Hilk Moderators last edited by

                          This is as good of a reason as it gets to write a small program, that does the work for you.

                          Recursively opening your source file folder and counting how often QIODevice::readline can be called.

                          Shouldn't take more than a few minutes to do.

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

                          Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


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

                          1 Reply Last reply Reply Quote 1
                          • mrjj
                            mrjj Lifetime Qt Champion @Pradeep P N last edited by

                            @Pradeep-P-N

                            sloccount topmost-source-code-directory
                            so like
                            sloccount c:\projects\testproject

                            https://www.dwheeler.com/sloccount/sloccount.html

                            1 Reply Last reply Reply Quote 1
                            • J.Hilk
                              J.Hilk Moderators last edited by

                              I had some time during breakfast :-)

                              #include <QCoreApplication>
                              #include <QDir>
                              #include <QFile>
                              #include <QTextStream>
                              #include <QVector>
                              
                              int countLines(QString path){
                                  QFile f(path);
                                  int cnt = 0;
                              
                                  if(f.open(QIODevice::ReadOnly | QIODevice::Text)){
                                      QTextStream read(&f);
                                      while(!read.atEnd()){
                                          read.readLine();
                                          cnt++;
                                      }
                                  }
                                  f.close();
                                  return cnt;
                              }
                              
                              int parseDir(QString path){
                                  int cnt = 0;
                                  QDir dir(path);
                                  QStringList dirs = dir.entryList(QDir::AllDirs |QDir::NoDotAndDotDot);
                                  QStringList file = dir.entryList(QDir::Files);
                                  for(QString dir : dirs){
                                          cnt += parseDir(path + "/"+dir);
                                  }
                              
                                  for(QString s : file){
                                      if(s.splitRef('.').last() == "h" || s.splitRef('.').last() == "cpp")
                                          cnt += countLines(path + "/"+s);
                                  }
                              
                                  return cnt;
                              }
                              
                              int main(int argc, char *argv[])
                              {
                                  QCoreApplication a(argc, argv);
                              
                                  int count = 0;
                              
                                  count += PathDir(a.arguments().last());
                              
                                  QTextStream out(stdout);
                                  out << "Lines in project: " << a.arguments().last() << ": "<< endl <<count << endl;
                              
                                  return a.exec();
                              }
                              

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

                              Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


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

                              jsulm 1 Reply Last reply Reply Quote 6
                              • jsulm
                                jsulm Lifetime Qt Champion @J.Hilk last edited by

                                @J.Hilk Well, it is a bit more complex :-) For example your version counts empty lines and comment lines.

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

                                J.Hilk 1 Reply Last reply Reply Quote 2
                                • J.Hilk
                                  J.Hilk Moderators @jsulm last edited by

                                  @jsulm well obviously :-P
                                  but that could be addressed e.g:

                                  int countLines(QString path){
                                      QFile f(path);
                                      int cnt = 0;
                                  
                                      if(f.open(QIODevice::ReadOnly | QIODevice::Text)){
                                          QTextStream read(&f);
                                          QString line;
                                          bool comment = false;
                                          while(!read.atEnd()){
                                              line = read.readLine();
                                              line = line.simplified();
                                              line.replace(" ","");
                                              if(line.size() >0){
                                                  if(line.leftRef(2) != "//"){
                                                      if(line.contains("/*"))
                                                          comment = true;
                                                      if(line.contains("*/"))
                                                          comment = false;
                                                      if(!comment)
                                                          cnt++;
                                                  }
                                              }
                                          }
                                      }
                                      f.close();
                                      return cnt;
                                  }
                                  

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

                                  Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


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

                                  1 Reply Last reply Reply Quote 2
                                  • Pradeep P N
                                    Pradeep P N last edited by

                                    Thanks All for the help.
                                    Moving to solved.

                                    Pradeep Nimbalkar.
                                    Upvote the answer(s) that helped you to solve the issue...
                                    Keep code clean.

                                    1 Reply Last reply Reply Quote 2
                                    • Kent-Dorfman
                                      Kent-Dorfman last edited by

                                      find and grep...find and grep

                                      aha_1980 1 Reply Last reply Reply Quote 0
                                      • aha_1980
                                        aha_1980 Lifetime Qt Champion @Kent-Dorfman last edited by

                                        @Kent-Dorfman would you like to elaborate a bit more?

                                        Qt has to stay free or it will die.

                                        1 Reply Last reply Reply Quote 2
                                        • W
                                          wrosecrans last edited by

                                          find . -iname \*.h -o -iname \*.cpp -exec grep \\\; {} \; | wc -l
                                          

                                          Would find all the .h and .cpp find in the current directory, and count the number of lines with a semicolon. For the most things, that's probably a pretty useful count of code LOC, and requires no extra tools to be installed.

                                          Pradeep P N 1 Reply Last reply Reply Quote 1
                                          • fcarney
                                            fcarney last edited by

                                            Is this for some kind of line-counting match?

                                            C++ is a perfectly valid school of magic.

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post