Results 1 to 2 of 2

Thread: Generated code and lupdate...

  1. #1
    Join Date
    Oct 2009
    Posts
    19
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Generated code and lupdate...

    Hi,

    I have implemented code generation in qmake as shown here: http://wiki.qtcentre.org/index.php?t...cumented_qmake

    Now I want to have translateable strings in the generated C++ source files. The only way this works right now is to manually specify all (generated) source files (as well as .ts files) on the command line when calling lupdate. Also I have to make sure to build the project right before calling lupdate... (otherwise, the generated sources might not exist, or might be out of date)...

    I would like to change this so that l can just call "lupdate test.pro" and it will automatically figure out the generated source files and build them if needed...

    Any ideas on how to do this?


    Example code, using "cp" as a code generator :-)

    test.pro:
    Qt Code:
    1. SOURCES=main.cpp
    2. TRANSLATIONS=test_de.ts
    3.  
    4. GEN_SOURCES = generated.gen
    5. gen.input = GEN_SOURCES
    6. gen.output = ${QMAKE_FILE_BASE}.cpp
    7. gen.commands = cp ${QMAKE_FILE_NAME} ${QMAKE_FILE_OUT}
    8. gen.variable_out = SOURCES
    9. QMAKE_EXTRA_COMPILERS += gen
    To copy to clipboard, switch view to plain text mode 

    generated.gen:
    Qt Code:
    1. #include <QCoreApplication>
    2. #include <iostream>
    3.  
    4. void helloWorld()
    5. {
    6. std::cout << qPrintable( QCoreApplication::translate( "fooBar", "Hello world!" ) ) << std::endl;
    7. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp:
    Qt Code:
    1. #include <QCoreApplication>
    2.  
    3. void helloWorld();
    4.  
    5. int main( int argc, char** argv )
    6. {
    7. QCoreApplication app( argc, argv );
    8. helloWorld();
    9. return 0;
    10. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Oct 2009
    Posts
    19
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Generated code and lupdate...

    I have changed the project file to make sure SOURCES always contains the generated files:

    test.pro:
    Qt Code:
    1. SOURCES = main.cpp
    2. TRANSLATIONS=test_de.ts
    3.  
    4. GEN_SOURCES = generated.cpp
    5. include( gen.pri )
    To copy to clipboard, switch view to plain text mode 

    gen.pri:
    Qt Code:
    1. SOURCES += $$GEN_SOURCES
    2. for( src, GEN_SOURCES ): GEN_INPUT += $$replace( src, .cpp, .gen )
    3.  
    4. gen.input = GEN_INPUT
    5. gen.output = ${QMAKE_FILE_BASE}.cpp
    6. gen.commands = cp ${QMAKE_FILE_NAME} ${QMAKE_FILE_OUT}
    7. gen.variable_out =
    8. QMAKE_EXTRA_COMPILERS += gen
    To copy to clipboard, switch view to plain text mode 

    Now when I invoke "lupdate test.pro" after the project was built, it works fine.

    The remaining problem is that it will fail silently if the project was not built and "generated.cpp" does not exist (not even a warning)!
    This is a problem to me since I might accidentally damage my translation files without even noticing if I forget to build the project before calling lupdate...

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.