Results 1 to 6 of 6

Thread: Code Completion in UI classes

  1. #1
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Question Code Completion in UI classes

    G'day All,

    Is there some trick to having Creator (1.1 on Linux, Qt 4.5.1) do code completion for Designer UI? Currently I get no useful completion after entering "m_ui->" with code straight from the Creator/Designer wizard (example below). I'm fairly sure this has worked in the past.

    Cheers,
    Chris
    Qt Code:
    1. #ifndef ALARMVIEW_H
    2. #define ALARMVIEW_H
    3.  
    4. #include <QtGui/QWidget>
    5.  
    6. namespace Ui {
    7. class AlarmView;
    8. }
    9.  
    10. class AlarmView : public QWidget {
    11. Q_OBJECT
    12. Q_DISABLE_COPY(AlarmView)
    13. public:
    14. explicit AlarmView(QWidget *parent = 0);
    15. virtual ~AlarmView();
    16.  
    17. protected:
    18. virtual void changeEvent(QEvent *e);
    19.  
    20. private:
    21. Ui::AlarmView *m_ui;
    22. };
    23.  
    24. #endif // ALARMVIEW_H
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #include "alarmview.h"
    2. #include "ui_alarmview.h"
    3.  
    4. AlarmView::AlarmView(QWidget *parent) :
    5. QWidget(parent),
    6. m_ui(new Ui::AlarmView)
    7. {
    8. m_ui->setupUi(this);
    9. m_ui-> // Completion fails here and only offers the class AlarmView and not the widgets
    10. }
    11.  
    12. AlarmView::~AlarmView()
    13. {
    14. delete m_ui;
    15. }
    16.  
    17. void AlarmView::changeEvent(QEvent *e)
    18. {
    19. QWidget::changeEvent(e);
    20. switch (e->type()) {
    21. case QEvent::LanguageChange:
    22. m_ui->retranslateUi(this);
    23. break;
    24. default:
    25. break;
    26. }
    27. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Posts
    98
    Thanks
    3
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Code Completion in UI classes

    Try to compile it, and then you should have the completion features.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Code Completion in UI classes

    Thanks.

    It was compiled on Gentoo and, for the most part, the completion works. Just the circumstances described above seem to break it. I've just done a quick rebuild to make sure that there were no broken deps. No change.

    Is there a cache of information that might be corrupt or need rebuilding?

  4. #4
    Join Date
    May 2009
    Posts
    15
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Code Completion in UI classes

    Qt Code:
    1. #include "ui_alarmview.h"
    To copy to clipboard, switch view to plain text mode 
    This file is auto generated from your .ui file. QtCreator doesn't have the current state of the file until it's compiled. So if you need autocompletion and make a change in the ui, you need to build again before you can use it.

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Code Completion in UI classes

    Thanks.

    I've built the example code (and lots of other examples) many times, no change
    It is not that it is not completing recent changes in the UI: it's not completing anything in the UI. The only thing in the completion drop-down is class "AlarmView" (from the Ui namespace) despite there being a QPushButton and QTableWidget in the UI.

    I have a separate build directory that ends up containing the ui_*.h files and other intermediates. Perhaps that is causing an issue. I'll do a quick experiment with everything in one directory.

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Code Completion in UI classes

    WOOHOO! It works if all is in one directory, but not if split.

    My pro file looks like:
    Qt Code:
    1. # -------------------------------------------------
    2. # Project created by QtCreator 2009-03-22T08:27:36
    3. # -------------------------------------------------
    4. QT += sql \
    5. svg
    6. CONFIG += qt \
    7. debug \
    8. warn_on
    9. TARGET = project
    10. TEMPLATE = app
    11. MOC_DIR = build
    12. OBJECTS_DIR = build
    13. RCC_DIR = build
    14. UI_DIR = build
    15. INCLUDEPATH += src
    16. VPATH = src \
    17. res
    18. HEADERS +=alarmview.h ...
    19. FORMS += alarmview.ui ...
    20. SOURCES += alarmview.cpp ...
    21. RESOURCES += project.qrc
    To copy to clipboard, switch view to plain text mode 
    Is there something I should tweak here? I've tried adding the build directory to INCLUDEPATH and VPATH: no dice.

Similar Threads

  1. Code completion for a Qwidget at Qt4 in QDevelop 4.3.1
    By sipklaus in forum Qt-based Software
    Replies: 3
    Last Post: 9th August 2010, 09:46
  2. Code completion in eclipse?
    By DeKay in forum Installation and Deployment
    Replies: 1
    Last Post: 14th August 2007, 06:17
  3. Code Completion in QScintilla
    By jpjimenez in forum Qt Programming
    Replies: 5
    Last Post: 13th July 2007, 21:42
  4. problem with linking
    By mickey in forum Qt Programming
    Replies: 49
    Last Post: 12th August 2006, 21:41
  5. MSVC6 + qt3-win-commercial = no code completion
    By a550ee in forum Installation and Deployment
    Replies: 1
    Last Post: 20th March 2006, 12:17

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.