Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

how to tell QtCreator to ignore one .cpp file.



  • Hi,
    I have a .cpp file containing only code snippets for my project documentation. I use Doxygen.

    // examples.cpp
    //! [ex1]
    if (index < 0 || index >= m_backends.size())
        return;
    //! [ex1]
    
    //! [ex2]
    QObject::connect(m_client.data(), &QOpcUaClient::stateChanged, this, &MachineBackend::clientStateHandler);
    //! [ex2]
    
    

    to use it

    // one "real" cpp file
    /// \snippet examples.cpp ex1
    if (index < 0 || index >= m_backends.size())
        return; // Invalid index
    

    Then i get the snippet as expected in the doc.

    Unfortunately i cannot compile my project with that examples.cpp file.

    Is this the right way to handle Doxygen snippets (with a separate file) ?
    i feel like it is not the right way because if i change my code i will have to manually adapt (copy/past) the new code in the snipetts file

    How to ignore that examples.cpp file so i can build my project again ?

    Thank you

    note : I did this separate file because if i add the snippet directly in the real code

    // the"real" cpp file
    
    //! [ex1]
    /// \snippet ThisFile.cpp ex1
    if (index < 0 || index >= m_backends.size())
        return; // Invalid index
    //! [ex1]
    

    this almost works, in the doc (generated html) i can see the snippet but i can also see the //![ex1]

    the output is exactly like this

    //! [ex1]
    /// \snippet ThisFile.cpp ex1
    if (index < 0 || index >= m_backends.size())
        return; // Invalid index
    //! [ex1]
    

  • Moderators

    @LeLev said in how to say QtCreator to ignore one .cpp file.:

    Unfortunately i cannot compile my project with thatexamples.cpp file.

    Is this the right way to handle Doxygen snippets (with a separate file) ?
    How to ignore that examples.cpp file so i can build my project again ?

    Do not put it in SOURCES in your qmake file. Only add it as input file in doxygen configuration file.


  • Moderators

    @LeLev said in how to say QtCreator to ignore one .cpp file.:

    Unfortunately i cannot compile my project with thatexamples.cpp file.

    Is this the right way to handle Doxygen snippets (with a separate file) ?
    How to ignore that examples.cpp file so i can build my project again ?

    Do not put it in SOURCES in your qmake file. Only add it as input file in doxygen configuration file.



  • @sierdzio thank you ! that worked.

    The annoying part is that i will have to change the examples manually if i change my code one day.

    Any solution to make this automated ?


  • Moderators

    @LeLev said in how to tell QtCreator to ignore one .cpp file.:

    @sierdzio thank you ! that worked.

    The annoying part is that i will have to change the examples manually if i change my code one day.

    Any solution to make this automated ?

    Well, define the snippet in real code. How is described here: http://doxygen.nl/manual/commands.html#cmdsnippet

    In your code I think you have an error that your put \snippet inside of `[ex1] markers. Remove that and it should work.



  • @sierdzio thx
    i have tryed like this also

        /// \snippet thisClassName.cpp ex1
        //! [ex1]
        QString program = "Gview.exe";
        QString filePath = file.replace("/","\\");
        QProcess *myProcess = new QProcess(this);
        myProcess->start(program, QStringList() << filePath ); 
        //! [ex1]
    

    but the output is still polluted with the special snippet markers

    output in the generated html page looks like :

        QString program = "GCodeView.exe";
        QString filePath = file.replace("/","\\");
        QProcess *myProcess = new QProcess(this);
        myProcess->start(program, QStringList() << filePath ); 
    [ex1]
    
    [ex1]
    

  • Moderators

    No idea, it looks like a doxygen bug perhaps? There is also the \dontinclude command which should work without the [ex1] markers.



  • @sierdzio said in how to tell QtCreator to ignore one .cpp file.:

    \dontinclude

    i'm fiddling with that one right now



  • @sierdzio said in how to tell QtCreator to ignore one .cpp file.:

    it looks like a doxygen bug perhaps

    yes it looks like a bug..

    the cleanest way i found is

        //! [ex1] \dontinclude
        QString program = "GView.exe";
        QString filePath = file.replace("/","\\");
        QProcess *myProcess = new QProcess(this);
        myProcess->start(program, QStringList() << filePath ); 
        //! [ex1] How to run <b>Gview.exe</b> ?
        //!\snippet machinebackend.cpp ex1
    
    

    the output is still polluted but it's ok for me

    output :

    [ex1] [ex1] How to run Gview.exe ?
    
        QString program = "GCodeView.exe";
        QString filePath = file.replace("/","\\");
        QProcess *myProcess = new QProcess(this);
        myProcess->start(program, QStringList() << filePath );
    

    Thank you again @sierdzio


Log in to reply