Why code completion does not work, what's wrong on my code?



  • @#include <QObject>
    #include <QStringList>

    class MyClass : public QObject
    {
    Q_OBJECT

    public:
    explicit MyClass(QObject *parent = 0);
    explicit MyClass(const MyClass &myclass, QObject *parent = 0);
    MyClass &operator=(const MyClass &myclass);
    QString &operator[](int i);

    public slots:
    void append(const QString &name);

    private:
    QStringList m_name;

    };

    //---------------------------------------------------------

    MyClass::MyClass(QObject *parent) :
    QObject(parent)
    {
    }

    MyClass::MyClass(const MyClass &myclass, QObject *parent) :
    QObject(parent)
    {
    *this = myclass;
    }

    MyClass &MyClass::operator =(const MyClass &myClass)
    {
    m_name = myClass.m_name;
    return *this;
    }

    QString &MyClass::operator [](int i)
    {
    return m_name[i];
    }

    void MyClass::append(const QString &name)
    {
    m_name.append(name);
    }

    //---------------------------------------------------------

    #include "mainwindow.h"
    #include "myclass.h"

    MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    {
    MyClass a;
    MyClass b(a);
    b[0]. // where code completion does not work.

    MyClass c;
    c = a;
    c[0]. // work fine.
    }@



  • Are you taking about auto complete in QtCreator IDE ? May be it is not able to identify 'b' as object due to default parameter. Create object with correct number of parameter in constructor

    e.g MyClass b(a,0);

    Then it start showing it. May be bug in QtCreator iDE.



  • Yes, it's in Qt Creator.
    If provide with full number of parameter it's work fine.
    I just worry about my code what I do wrong why IDE can't detect.
    So it's just a bug?


Log in to reply
 

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