QtCreator plugin for cppcheck, krazy and other tools



  • Hello,

    This tool can used as qtcreator plugin to some other tools when using project files managed by qmake.

    homepage is https://sourceforge.net/projects/qtprojecttool/

    A manual and configuration files can be found at https://sourceforge.net/projects/qtprojecttool/files/

    It works in Qt4 and Qt5.

    Regards,
    Carlos


  • Moderators

    How does that Creator plugin work?

    You seem to just call the command line tool... how do you get the output from there into the build issues?



  • Hi,

    When running inside Creator you must use the switch -qtc-plugin, it generates the issue pane.

    The information in issues pane is generated after "cppcheck" or "krazy" finishes.

    In the manual, the chapter "3 Using “qpt” with QtCreator (qtcreator)" gives an example.

    Best Regards,
    Carlos


  • Moderators

    How does it work technically? Is your plugin parsing the output of those tools and inserts the issues itself or is it using the task list plugin to display the list of issues?



  • When --qtc-plugin is NOT present, it just prints out the commands output "cppcheck" or "krazy"

    When --qtc-plugin is present, it does:

    parses the command output generating a tasks files,

             see http://qt-project.org/doc/qtcreator-2.6/creator-task-lists.html
    

    call qtcreator back using the options: -client -pid, passing the tasks file, then qtcreator opens the tasks file and put the content into issues pane

    After few time removes the tasks file

    So, if you execute the "qpt" outside qtcreator using --qtc-plugin it should also works.


  • Moderators

    Cool, thanks for the information.



  • Hi,
    Is your plugin supposed to compile under Windows?



  • Yes, I took some care of it.

    But I have not tested it since I do not use Windows.

    If you have any problem let me know.



  • my compiler doesn't seem to find include file
    #include <unistd.h>

    As far as I understand, it's a unix file only



  • YES, it is, try to remove this line.



  • by removing that line, I have the following error

    qcommandline.cpp:32:
    error: C2491: 'QCommandLine::helpEntry' : definition of dllimport static data member not allowed



  • I am using this module QCommandLine, it is also open source and I got it from http://xf.iksaif.net/dev/qcommandline.html.

    I am sorry, I am not able to help at this point unless I try to compile on Windows, I do not have any Windows compiler.

    I think that is in the link process and you are close to compile it.

    Once you get it compiled, qmake and qtcreator must be in the PATH in order to work.

    Try to research about this problem or contact the QCommandLine author.



  • I would recommend it, but given the hassle to set things up I'd give 4/5 stars. In addition to the manual, using windows there are couple of things to bear in mind:

    • in the arguments field during setting up, be aware that unless you set cppcheck in your environment paths, "--tool=cppcheck" does not work. You'll need to set the directory:

    @--qtc-plugin --tool="C:/Cppcheck-1.55/cppcheck.exe" %{CurrentProject:FilePath} @

    • You'll need to set an environment paths to QtCreator(usually in C:\Qt\Qt5.0.2\Tools\QtCreator\bin). Without this the warning messages from cppcheck does not show up in the issues pane
    • Don't use cppcheck 1.60. In qpt 0.7, it doesn't work. I got things running with cppcheck 1.55.

    And thus, a happy user of QtProjectTool! :D

    !https://lh6.googleusercontent.com/-byu0-9Dqaro/UayAScAJ3gI/AAAAAAAABWc/nw5Ld_YStvw/w617-h585-no/QtProjectTool+Screenshot.png(QtProjectTool running in windows 7)!

    windows 7 32bit, Qt 5.0.2 MinGW, cppcheck 1.55



  • OK, Thanks.

    I got a Windows machine and I am able to work on that now.

    qpt 0.8 version will work better on Windows and the manual will be updated.



  • Not a very good method for tool version check:
    you are getting the numeric part and blindly converting to double. Well, it's a bit optimistic assumption that a version number will be a valid numeric value!

    In fact, now that cppcheck went up to version 1.60.1, QPT happily states that "Tool cppcheck-gui requires a minimal version 1.55".



  • It is a bug and will be fixed soon.

    As a work around try to edit the configuration file, qpt prints the path of the configuration file when it starts.
    It is usually located at $HOME/.config/QtProjectTool/qpt.ini

    try to clear the minimal version line, change:

    Mininal_version_USE_only_digist_and_dot_it_will_be_converted_to_float=1.58

    to

    Mininal_version_USE_only_digist_and_dot_it_will_be_converted_to_float=

    That should work.



  • I did it the other way :)
    Created a QByteArray w2 where to copy all the numbers without any punctuation sign. So 1.60.1 ends up being 1601 which is greater than 1.55
    Maybe it's a good idea for version checking (I didn't stop to think about implications of doing this... it was just a workaround)



  • Hello,

    Version 0.8 has been released with some improvements, see "RELEASE NOTES":http://sourceforge.net/projects/qtprojecttool/files/RELEASE_NOTES.txt/download



  • Version 0.8 has been released with some improvements, the main work was done to have a better Windows version.

    See "RELEASE NOTES":http://sourceforge.net/projects/qtprojecttool/files/RELEASE_NOTES.txt/download



  • Thank you for your tool! But I get question marks in the file paths with non-latin letters (e.g. cyrillic letters)
    @$qpt -A CET.pro

    /home/alex/Projects/??????/src/main.cpp
    /home/alex/Projects/??????/src/mainwindow.cpp
    /home/alex/Projects/??????/src/mainwindow.h@



  • Hi,

    Are you using version 0.8 ?

    send me your project file and the right path it should bring,

    I will take a look on that.

    Thanks, Carlos



  • Yes, the version is 0.8. I sent you a tarball, thanks for your fast respond



  • Hi, it has been fixed (not published yet)

    bq. ./qpt -A /home/carlos/tmp/projects/qpt_tests/Проекты/КириллическоеИмяПроекта/hello.pro
    /home/carlos/tmp/projects/qpt_tests/Проекты/КириллическоеИмяПроекта/hello.cpp

    But, I am afraid cppcheck does not handle unicode paths:

    /usr/bin/cppcheck --platform=unix32 -I . -f -q --template '{file}:{line}:{id}:{message}' --inline-suppr --enable=style --enable=unusedFunction --suppress=missingInclude:* --inconclusive --file-list=/tmp/qt_temp.Lh2660

    cppcheck: error: could not find or open any of the paths given.

    I use full pathname for files, I will try using relative pathnames.



  • [quote author="cmazieri" date="1377213999"]
    But, I am afraid cppcheck does not handle unicode paths:

    /usr/bin/cppcheck --platform=unix32 -I . -f -q --template '{file}:{line}:{id}:{message}' --inline-suppr --enable=style --enable=unusedFunction --suppress=missingInclude:* --inconclusive --file-list=/tmp/qt_temp.Lh2660

    cppcheck: error: could not find or open any of the paths given.

    I use full pathname for files, I will try using relative pathnames.
    [/quote]

    No, cppcheck is all right. This is what I get with cppcheck 1.60.1

    @$ cat list
    /home/alex/Проекты/КириллическоеИмяПроекта/hello.cpp

    $ /usr/bin/cppcheck --platform=unix32 -I . -f -q --template ‘{file}:{line}:{id}:{message}’ --inline-suppr --enable=style --enable=unusedFunction --suppress=missingInclude:* --inconclusive /home/alex/Проекты/КириллическоеИмяПроекта/hello.cpp --file-list=list
    ‘/home/alex/Проекты/КириллическоеИмяПроекта/hello.cpp:9:unreadVariable:Variable 'a' is assigned a value that is never used.’
    ‘/home/alex/Проекты/КириллическоеИмяПроекта/hello.cpp:9:arrayIndexOutOfBounds:Array 'a[5]' accessed at index 5, which is out of bounds.’@



  • Hi,

    Many Thanks,

    I had no Unicode handling in qpt, it has been included.

    Please get version "0.9":http://sourceforge.net/projects/qtprojecttool/files/0.9/qpt-source-0.9.tgz/download and let me know if you have any problem.

    Regards,

    bq.
    [qpt running]: /usr/bin/cppcheck --platform=unix32 -I . -f -q --template '{file}:{line}:{message}' --inline-suppr --enable=style --enable=unusedFunction --inconclusive /home/carlos/tmp/projects/tests/test/Проекты/КириллическоеИмяПроекта/hello.cpp /home/carlos/tmp/projects/tests/test/Проекты/КириллическоеИмяПроекта/mz.cpp /home/carlos/tmp/projects/tests/test/Проекты/КириллическоеИмяПроекта/ры.cpp'/home/carlos/tmp/projects/tests/test/Проекты/КириллическоеИмяПроекта/hello.cpp:5:Variable 'x' is not assigned a value.'
    '/home/carlos/tmp/projects/tests/test/Проекты/КириллическоеИмяПроекта/mz.cpp:3:Unused variable: ret'
    '/home/carlos/tmp/projects/tests/test/Проекты/КириллическоеИмяПроекта/mz.cpp:4:Variable 'x' is not assigned a value.'
    '/home/carlos/tmp/projects/tests/test/Проекты/КириллическоеИмяПроекта/ры.cpp:3:Unused variable: ret'
    '/home/carlos/tmp/projects/tests/test/Проекты/КириллическоеИмяПроекта/ры.cpp:4:Variable 'x' is not assigned a value.'
    '/home/carlos/tmp/projects/tests/test/Проекты/КириллическоеИмяПроекта/mz.cpp:1:The function 'x' is never used.'



  • Hi,

    this is a great tool. However, my top-level project file is of type "subdirs" and thus no sources are listed. Nevertheless it would be great to have this tool parsing recursively the .pro-file(s) below.

    Can this be done?

    Regards,

    Thorsten



  • No,
    qpt uses qmake to expose SOURCES and HEADERS.
    A subdir project does not have it, at least I do not know.

    What I do is: create a dummy project file that includes all other projects, like this:

    my_cppcheck_code.pro
    @
    BASE = snapshot_8_22_2013

    include ($$BASE/Ldap/test/regression_ldap.pro)
    include ($$BASE/ProcessWindow/test/regression_jobwindow.pro)
    include ($$BASE/commonLib/cmntrace/test/cmntrace.pro)
    include ($$BASE/commonLib/cmncli/test/cmncli.pro)
    include ($$BASE/ComboSearch/ComboSearch.def)
    include ($$BASE/customHeader/test/customtable.pro)
    include ($$BASE/DictPointer/DictPointer.def)
    include ($$BASE/diskspace/test/diskspace.pro)
    include ($$BASE/FileUtil/FileUtil.def)
    include ($$BASE/Ldap/Ldap.def)
    include ($$BASE/Preferences/test/regression_PreferencesEditor.pro)
    include ($$BASE/Tickets/Tickets.def)
    include ($$BASE/UiUtils/UiUtils.def)
    include ($$BASE/tests/regression_pipa.pri)
    @

    Then use that dummy project my_cppcheck_code.pro to run qpt/cppcheck. You can have all those projects opened in QtCreator, so set the dummy as default to run qpt, then set the original project back as default to compile.

    By the way, I am having problems to make this change work on Windows, the path comes undefined from command qpt command line.

    Regards,
    Carlos



  • Thanks a lot, cyrillic names work like a charm!

    Is it possible to get support of subdirs projects? I've tried the method you suggested but with no result. I sent you a tarball with project I used, if you have time to take a look



  • You have to include $$PWD in SOURCES and HEADERS in your .pro files, like this:
    @
    SOURCES += $$PWD/main.cpp
    $$PWD/mainwindow.cpp

    HEADERS += $$PWD/mainwindow.h

    FORMS += $$PWD/mainwindow.ui
    @

    I used your subdirs-project-cppcheck.pro and I put an issue in main.cpp to test that:
    @Starting external tool 'C:/Users/b35201/Downloads/build-qprojtool-Qt_4_85_static-Release/release/qpt.exe' -t cppcheck -q C:/Users/b35201/Downloads/subdirs-project/subdirs-project-cppcheck.pro
    qpt.exe using: C:/Users/b35201/AppData/Roaming/QtProjectTool/qpt.exe.ini

    [qpt.exe running]: "C:/Program Files/Cppcheck/cppcheck.exe" --platform=win32W -I . -DUNICODE -DWIN32 -f -q --template '{file}:{line}:{message}' --inline-suppr --enable=all --inconclusive --file-list=C:/Users/b35201/AppData/Local/Temp/qt_temp.Uh7436

    'C:\Users\b35201\Downloads\subdirs-project\tests\test1\main.cpp:5:Variable 'x' is not assigned a value.'
    '::Cppcheck cannot find all the include files (use --check-config for details)'

    [qpt.exe INFO]: "C:/Program Files/Cppcheck/cppcheck.exe" finished with return code 0

    [qpt.exe running]: C:/Qt/Qt5.0.2/Tools/QtCreator/bin/qtcreator.exe -client C:/Users/b35201/AppData/Local/Temp/qpt.exe0737323847436.tasks

    [qpt.exe INFO]: finished with return code 0

    'C:/Users/b35201/Downloads/build-qprojtool-Qt_4_85_static-Release/release/qpt.exe' finished@

    I will add this procedure in the qpt manual.

    Thanks,
    Carlos



  • Thanks, I got you

    I have several issues/suggestions:

    The most odd thing: launching cppcheck from external tools in QtCreator gives me one new instance of QtCreator (in addition to one I already have) Oo

    Your way with additional .pro-file works, but I have no output in "Issues" tab of QtCreator

    I believe, that it would be a better design to make qpt parsing subdirs-projects correctly, it is just recursive walking through the project tree, isn't it?



    1. Will check that, in my test on Windows it works:
      (messages pane) https://www.dropbox.com/s/aez4b2325ov0903/general_messages.png
      (issues pane) https://www.dropbox.com/s/9kvd13exo16blcl/issues.png

    2. check it there were issues, in the test you sent me I had change one file in order to have an issue.

    3. Next release perhaps.



    1. "This":http://i41.tinypic.com/25i1wr5.png is what I get


  • OK, I see.

    I have just posted a new version "0.9":http://sourceforge.net/projects/qtprojecttool/files/0.9/qpt-source-0.9.tgz/download over the previous version.
    I have tested this version against several qtcreator versions I have, Qt4 and Qt5, the only difference that can make explain somethingis that which has QTimer::singleShot(3800, ..).

    If it still does not work, try to increase that value and see if it works.

    @diff -w 09/src/backendtool.cpp 09-ok/src/backendtool.cpp
    204c204,206
    <

    #if DEBUG
    qDebug() << Q_FUNC_INFO << "cmd" << cmd;
    #endif
    273a276,281
    if (m_taskFile)
    {
    QTimer::singleShot(3800, this, SLOT(finishQtcPluginInvoke()));
    }
    else
    {
    275a284
    }
    356,357d364
    < if (QFile(fields[0]).exists())
    < {
    361a369,370
    if (fields.count() > 1 && QFile(fields[0]).exists())
    {
    398c407
    < qDebug() << Q_FUNC_INFO << taskFile() << "ret" << ret;


    qDebug() << Q_FUNC_INFO << taskFile&#40;&#41; << "ret" << ret << "size" << m_taskFile->size();
    

    419d427
    <
    445,446c453,454
    < qDebug() << "plugin" << qtcreator;
    < #endif

    m_taskFile->copy("taskfile_deb.task");
    

    #endif //DEBUG
    451a460,463
    else
    {
    Util::info(qtcreator, QLatin1String("running"));
    }
    @

    Please let me know if it solves the problem or not.

    Regards,
    Carlos



  • Hey there! First of all thanks for making this tool, very much appreciated!

    It works flawlessly on OSX, but I notice that there is an issue with qmake projects using the SUBDIRS template. Indeed there are no .cpp files on the main project file itself, so one has to individually select each subfolder and run the code on there. (otherwise the list of files created and passed to cppcheck/razy is empty)

    To have it running on qt creator I just changed %{CurrentProject:FilePath} into %{CurrentDocument:FilePath} and launch the tool from within each .pro file in the subfolders.



  • Hey,

    Many thanks for the information, I will try this out.

    Anyway, in the previous page there is another way of getting SUBDIRS qmake project working.



  • About the problem with the second instance of QtCreator and no issues found -- totaly my fault, I've had poorly written script that launches QtCreator

    Thanks for your help



  • Hello All,

    Version 1.0 is available.

    Added support to subdirs projects.

    Many thanks to Serhiy Moroz.



  • Cool, excellent job!



  • it's working.
    There is the plugin 1.2version.
    After installation , need Tools->External->Configure...->cppcheck set Executable field to the qpt binary file path.
    or in ~/.bashrc
    @PATH=qpt_execute_path:$PATH@



  • Hi,

    Issues pane is empty when using qpt in QtCreator on windows OS. I am using qpt 1.2, cppcheck 1.66, Qt 3.1.2. I followed all steps which are required for integrating qpt into Qt. But issues pane is empty. Anyone faced the same problem? Any help is appreciated. 
    

    Thanks & Regards.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.