undefined reference to



  • @#include "video.h"
    #include "networkaccess.h"
    #include <QtNetwork>
    #include "videodefinition.h"

    namespace The {
    NetworkAccess* http();
    }

    Video::Video() : m_duration(0),
    m_viewCount(-1),
    definitionCode(0),
    elIndex(0),
    loadingStreamUrl(false)
    { }

    void Video::preloadThumbnail() {
    if (m_thumbnailUrls.isEmpty()) return;
    QObject *reply = The::http()->get(m_thumbnailUrls.first());
    connect(reply, SIGNAL(data(QByteArray)), SLOT(setThumbnail(QByteArray)));
    }
    @

    Whenever i use the above code im getting the following error
    ./release\video.o:video.cpp:(.text+0x49): undefined reference to `The::http()'

    Can someone help me on this..Thanks in advance.



  • @namespace The {
    NetworkAccess* http();
    }@

    You declare this function, but nowhere implemented it.



  • [quote author="sathism" date="1293777356"]@
    namespace The {
    NetworkAccess* http();
    }

    Video::Video() : m_duration(0),
    m_viewCount(-1),
    definitionCode(0),
    elIndex(0),
    loadingStreamUrl(false)
    { }
    @

    [/quote]

    Also what does this lines do. Are they inside any function.



  • [quote author="QtK" date="1293783653"]
    [quote author="sathism" date="1293777356"]@
    namespace The {
    NetworkAccess* http();
    }

    Video::Video() : m_duration(0),
    m_viewCount(-1),
    definitionCode(0),
    elIndex(0),
    loadingStreamUrl(false)
    { }
    @

    [/quote]

    Also what does this lines do. Are they inside any function.
    [/quote]

    I think that this is a construct function with list of initialization(i don't sure how it's named in english) from class Video who is in video.h file



  • [quote author="BlackDante" date="1293791754"]
    [quote author="QtK" date="1293783653"]
    [quote author="sathism" date="1293777356"]@
    namespace The {
    NetworkAccess* http();
    }

    Video::Video() : m_duration(0),
    m_viewCount(-1),
    definitionCode(0),
    elIndex(0),
    loadingStreamUrl(false)
    { }
    @

    [/quote]

    Also what does this lines do. Are they inside any function.
    [/quote]

    I think that this is a construct function with list of initialization(i don't sure how it's named in english) from class Video who is in video.h file [/quote]

    Oh no it seems I am gone blind :) I didn't notice this Video::Video() properly.

    Thank you.



  • QtK, BlackDante are right, It's implementation empty constructor with list of initialization values.



  • [quote author="Vass" date="1293792450"]QtK, BlackDante are right, It's implementation empty constructor with list of initialization values.[/quote]

    Yes, As mentioned above I had not noticed it properly. Don't know how I missed it.



  • This is no problem, sometimes everyone can miss somethink. :) it's in human nature :)



  • [quote author="Vass" date="1293779836"]@namespace The {
    NetworkAccess* http();
    }@

    You declare this function, but nowhere implemented it.[/quote]

    This should be the problem. Something like this should solve it:

    @
    #include "video.h"
    #include "networkaccess.h"
    #include <QtNetwork>
    #include "videodefinition.h"

    namespace The {
    NetworkAccess* http()
    {
    return 0;
    }
    }

    Video::Video() :
    m_duration(0),
    m_viewCount(-1),
    definitionCode(0),
    elIndex(0),
    loadingStreamUrl(false)
    { }

    void Video::preloadThumbnail()
    {
    if (m_thumbnailUrls.isEmpty()) return;
    QObject *reply = The::http()->get(m_thumbnailUrls.first());
    connect(reply, SIGNAL(data(QByteArray)), SLOT(setThumbnail(QByteArray)));
    }
    @



  • Please ignore if you actually want the http to be a function
    But i have a feeling that the OP didn't want a function there, so here is my explanation about this line of code:
    @NetworkAccess* http();@
    The C++ compiler threats all the "things" that might be a function declaration, like there really are function declaration, so the compiler thinks: NetworkAccess pointer is the return type, http is the function name and () the function has no parameters.

    If you want an object on the stack you will write this:
    @NetworkAccess http; //no pointer and no () for default constructor
    @
    If you want/need to use pointers, you need two objects: the pointer and the object itself, that is done usually by using the operator new to allocate memory and call the constructor of the object (or using the address-of operator to take the address of a previously created object), code (for operator new) looks like this:
    @NetworkAccess* http = new NetworkAccess(); //here you can have () for default constructor ;)
    @



  • Thanks for all your valuable replies.
    @Gerolf
    I will try your fix ..



  • [quote author="Gerolf" date="1293806305"]
    This should be the problem. Something like this should solve it:

    @
    #include "video.h"
    #include "networkaccess.h"
    #include <QtNetwork>
    #include "videodefinition.h"

    namespace The {
    NetworkAccess* http()
    {
    return 0;
    }
    }

    Video::Video() :
    m_duration(0),
    m_viewCount(-1),
    definitionCode(0),
    elIndex(0),
    loadingStreamUrl(false)
    { }

    void Video::preloadThumbnail()
    {
    if (m_thumbnailUrls.isEmpty()) return;
    QObject *reply = The::http()->get(m_thumbnailUrls.first());
    connect(reply, SIGNAL(data(QByteArray)), SLOT(setThumbnail(QByteArray)));
    }
    @[/quote]

    Gerolf, you code will be crashed on line 25:
    @ QObject *reply = The::http()->get(m_thumbnailUrls.first());@
    because The::http() return null pointer.



  • It was to show, what is missing. I didn't implement the method, that's something you have to do :-)



  • Gerolf I understood :) I just saw sathism will try your fix, and warned about problem.


Log in to reply
 

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