Results 1 to 1 of 1

Thread: lupdate fails to detect context for class in namespace

  1. #1
    Join Date
    Oct 2012
    Posts
    132
    Thanks
    10
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Question lupdate fails to detect context for class in namespace

    Hi,

    I put all the classes of my application into certain namespaces. Now I wanted to generate ts-files using lupdate.

    Generally this works fine, but for some classes the context is not set properly - the namespace is missing.

    QtGui::MainWindows is such a class:
    Qt Code:
    1. #include <QPlainTextEdit>
    2. #include <QWebFrame>
    3. #include <QWebPage>
    4.  
    5. #include <list>
    6. #include <thread>
    7. #include <sstream>
    8. #include <iomanip>
    9. #include <functional>
    10.  
    11. using namespace std;
    12. using namespace UtilityFeatures;
    13. using namespace Media;
    14.  
    15. namespace QtGui {
    16.  
    17. /*
    18.   TRANSLATOR QtGui::MainWindow
    19.   Necessary for lupdate.
    20. */
    21.  
    22. MainWindow::MainWindow(QWidget *parent) :
    23. QMainWindow(parent, Qt::Window),
    24. // .....
    To copy to clipboard, switch view to plain text mode 
    Because the context can not be detected I added a translator comment before the first definition as you can see. This doesn't help.

    For some other classes the namespace detection works fine:
    Qt Code:
    1. // .....
    2. #include <QScriptEngine>
    3. #include <QScriptProgram>
    4.  
    5. using namespace std;
    6.  
    7. namespace RenamingUtility {
    8.  
    9. /*
    10.   TRANSLATOR RenamingUtility::RemamingEngine
    11.   Necessary for lupdate.
    12. */
    13.  
    14. RemamingEngine::RemamingEngine(QObject *parent) :
    15. QObject(parent),
    16. // ....
    To copy to clipboard, switch view to plain text mode 
    As you can see I added here a translator comment as well. But it seems to be unnecessary since the namespace can be detected without as well. Nevertheless the comment gets noticed as hint in Qt Assistant.

    There is no difference between these two classes/namespaces except one: The QtGui namespace is also populated by Ui classes generated from ui-files.
    Qt Code:
    1. <class>QtGui::MainWindow</class>
    2. <widget class="QMainWindow" name="QtGui::MainWindow">
    To copy to clipboard, switch view to plain text mode 
    The context for the "designer strings" of the MainWindow class is correctly.

    Consequently I'm getting the context "QtGui::MainWindow" in my ts-files which contains all "designer strings" and a context "MainWindow" which contains regular strings wrapped using tr(). Strangely the context "QtGui::MainWindow" also contains the translator comment I added for QtGui::MainWindow in mainwindow.cpp as last "entry".

    This seems to be the source of the problem, but I don't know how to fix it. I'm hoping someone can help here. Maybe I've discovered a bug of lupdate here and there is a simple workaround possible.

    EDIT: I forgot to post the message lupdate prints for classes like QtGui::MainWindow:
    ......./gui/mainwindow.cpp:214: Qualifying with unknown namespace/class ::MainWindow
    EDIT 2: Solved it.
    I figured out that the fact that the QtGui namespace is also populated by Ui classes doesn't cause the problem.
    The problem is cause somewhere else: The forward declaration of an enum. This is possible when the base type is specified.
    Qt Code:
    1. enum class MyEnum : int;
    To copy to clipboard, switch view to plain text mode 
    http://www.open-std.org/jtc1/sc22/wg...2008/n2764.pdf

    Unfortunately lupdate can not handle this synatax. I walk around that problem using a macro:
    Qt Code:
    1. #define DECLARE_ENUM(name, base) enum class name : base;
    2. DECLARE_ENUM(MyEnum, int)
    To copy to clipboard, switch view to plain text mode 
    It works but looks very ugly. Maybe I'd rather include the header.
    Last edited by Infinity; 3rd July 2014 at 20:55.

Similar Threads

  1. lupdate problem
    By cejot in forum Qt Programming
    Replies: 4
    Last Post: 4th September 2013, 10:14
  2. lupdate errors?
    By nthung in forum Newbie
    Replies: 3
    Last Post: 13th October 2011, 13:17
  3. Problem with lupdate
    By loris128 in forum Qt Tools
    Replies: 3
    Last Post: 8th April 2009, 20:36
  4. Queued connection fails on own class
    By ^NyAw^ in forum Qt Programming
    Replies: 3
    Last Post: 2nd December 2008, 18:50
  5. 4.2 and lupdate
    By Byngl in forum Qt Programming
    Replies: 3
    Last Post: 12th November 2007, 03:55

Tags for this Thread

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.