How the Qt source code is organized

天涯浪子 提交于 2019-12-12 04:58:39

问题


I am trying to find the Qt implementation for QLinkedList::operator+( const QLinkedList<T> &list ), but I can't make sense of the Qt source code. This is part of Qt 4.8.4:

I found the declaration in the .h:

QLinkedList<T> operator+(const QLinkedList<T> &l) const;

But in the .cpp all I see is this:

/*! \fn QLinkedList<T> QLinkedList::operator+(const QLinkedList<T> &other) const

    Returns a list that contains all the items in this list followed
    by all the items in the \a other list.

    \sa operator+=()
*/

Where is the definition? What organization is Qt using?


回答1:


Without looking too closely, the implementation seems to be in src/corelib/tools/qlinkedlist.h (you can view this file here: http://qt.gitorious.org/qt/qt/blobs/4.8/src/corelib/tools/qlinkedlist.h).

In particular, most of the functions are defined in one or two lines near the top of the file (lines 78 through 255 in the file I linked). These are using some longer functions to do the work (a fair portion of which are not accessible via the public Qt API), which are defined on lines 258 through 516 in the file I linked.

Beause QLinkedList is a template, it make sense for the implementation to be entirely in the header (in fact, you "can't" [I use the term loosely] put the implementation in a C++ file). For a more in-depth explanation of how this works, see this question: Why can templates only be implemented in the header file?.

The specific function you mention, QLinkedList::operator+(const QLinkedList<T> &list), is defined on line 511 of the file I linked.




回答2:


The definition of QLinkedList<T>::operator+(const QLinkedList<T>& l) is also inside qlinkedlist.h at the bottom.

This is the definition:

template <typename T>
QLinkedList<T> QLinkedList<T>::operator+(const QLinkedList<T> &l) const
{
    QLinkedList<T> n = *this;
    n += l;
    return n;
}

Source: http://qt.gitorious.org/qt/qt/blobs/v4.8.4/src/corelib/tools/qlinkedlist.h



来源:https://stackoverflow.com/questions/17240766/how-the-qt-source-code-is-organized

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!