Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 2

Qt-interest Archive, May 2007
link problem of 'static QPtrList<QListViewItem> p_listviewitem '


Message 1 in thread

hi again today

i define a static member in my code


class LVIPtr
{
public :
             static QPtrList<QListViewItem> p_listviewitem;
             static void setupListviewPoint();
//...........
};
void LVIPtr::setupListviewPoint()
{
             do something like  p_listviewitem.append ;
}

and in another class
class myApps
{
        public:
        void  getPtr();
}
void myApps::getPtr()
{
       QPtrList<QListViewItem> ptr=LVIPtr::p_listviewitem;
//..........
}

gcc said:
apps.o: In function
`QPtrList<QListViewItem>::operator=(QPtrList<QListViewItem> const&)':
/usr/lib/qt/include/qptrlist.h:72: undefined reference to
`LVIPtr::p_listviewitem'
lviptr.o: In function `QPtrList<QListViewItem>::append(QListViewItem const*)':
/usr/lib/qt/include/qptrlist.h:82: undefined reference to
`LVIPtr::p_listviewitem'
/usr/lib/qt/include/qptrlist.h:82: undefined reference to
`LVIPtr::p_listviewitem'
lviptr.o: In function `QPtrList<QListViewItem>::first()':
/usr/lib/qt/include/qptrlist.h:109: undefined reference to
`LVIPtr::p_listviewitem'
lviptr.o: In function `QPtrList<QListViewItem>::next()':
/usr/lib/qt/include/qptrlist.h:111: undefined reference to
`LVIPtr::p_listviewitem'
collect2: ld returned 1 exit status
make: *** [apps] Error 1

what's the problem?
then i tried to define it:
QPtrList<QListViewItem> LVIPtr::p_listviewitem;
in main
gcc said:
main.cc: In function 'int main(int, char**)':
main.cc:26: error: invalid use of qualified-name 'LVIPtr::p_listviewitem'
make: *** [main.o] Error 1

how to do this?
regards

--
 [ signature omitted ] 

Message 2 in thread

On 07.05.07 00:29:44, jiang jefix wrote:
> i define a static member in my code
> class LVIPtr
> {
> public :
>             static QPtrList<QListViewItem> p_listviewitem;
>             static void setupListviewPoint();
> //...........
> };
> void LVIPtr::setupListviewPoint()
> {
>             do something like  p_listviewitem.append ;
> }
> 
> and in another class
> class myApps
> {
>        public:
>        void  getPtr();
> }
> void myApps::getPtr()
> {
>       QPtrList<QListViewItem> ptr=LVIPtr::p_listviewitem;
> //..........
> }
> 
> gcc said:
> apps.o: In function
> `QPtrList<QListViewItem>::operator=(QPtrList<QListViewItem> const&)':
> /usr/lib/qt/include/qptrlist.h:72: undefined reference to
> `LVIPtr::p_listviewitem'

This means that you don't link against the library in which LVIPtr is,
so just add that library via the .pro file that builds apps.o like this:

LIBS += path-to-lib/libname.a

If its a static lib. If you build a shared lib you'd need something like

LIBS += -lname -Lpath-to-lib

Andreas

-- 
 [ signature omitted ] 

Message 3 in thread

maybe i dont say clear
note that LVIPtr is a class i defined in my apps
it has a static member:
static QPtrList<QListViewItem> p_listviewitem;

and in another class myApps:
i want to get p_listviewitem which is a static member defined in class LVIPtr
class myApps
{
        void getPtr();
//........
};

void myApps::getPtr()
{
QPtrList<QListViewItem> *ptr=LVIPtr::p_listviewitem;       // this is
line 189 in //apps.cc
//............
}

and gcc said:
apps.o: In function `myApps::getPtr()':
/home/jefix/study/qt/myapps/apps.cc:189: undefined reference to
`LVIPtr::p_listviewitem'
collect2: ld returned 1 exit status
make: *** [apps] Error 1

what's the problem?
thanks

2007/5/7, Andreas Pakulat <apaku@xxxxxx>:
> On 07.05.07 00:29:44, jiang jefix wrote:
> > i define a static member in my code
> > class LVIPtr
> > {
> > public :
> >             static QPtrList<QListViewItem> p_listviewitem;
> >             static void setupListviewPoint();
> > //...........
> > };
> > void LVIPtr::setupListviewPoint()
> > {
> >             do something like  p_listviewitem.append ;
> > }
> >
> > and in another class
> > class myApps
> > {
> >        public:
> >        void  getPtr();
> > }
> > void myApps::getPtr()
> > {
> >       QPtrList<QListViewItem> ptr=LVIPtr::p_listviewitem;
> > //..........
> > }
> >
> > gcc said:
> > apps.o: In function
> > `QPtrList<QListViewItem>::operator=(QPtrList<QListViewItem> const&)':
> > /usr/lib/qt/include/qptrlist.h:72: undefined reference to
> > `LVIPtr::p_listviewitem'
>
> This means that you don't link against the library in which LVIPtr is,
> so just add that library via the .pro file that builds apps.o like this:
>
> LIBS += path-to-lib/libname.a
>
> If its a static lib. If you build a shared lib you'd need something like
>
> LIBS += -lname -Lpath-to-lib
>
> Andreas
>
> --
> Good news.  Ten weeks from Friday will be a pretty good day.
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>

--
 [ signature omitted ] 

Message 4 in thread

This is a C++ error.

Static class member variables have to be instantiated/initialized outside of the
class declaration. Example:

// declare the class in file foo.hxx
class foo_t
{
public:
  static int bar_;
};

// initialize foo_t::bar_ in file foo.cxx
int foo_t::bar_ = 0;

Hope this helps,
	Paul.


jiang jefix wrote:
> maybe i dont say clear
> note that LVIPtr is a class i defined in my apps
> it has a static member:
> static QPtrList<QListViewItem> p_listviewitem;
> 
> and in another class myApps:
> i want to get p_listviewitem which is a static member defined in class
> LVIPtr
> class myApps
> {
>        void getPtr();
> //........
> };
> 
> void myApps::getPtr()
> {
> QPtrList<QListViewItem> *ptr=LVIPtr::p_listviewitem;       // this is
> line 189 in //apps.cc
> //............
> }
> 
> and gcc said:
> apps.o: In function `myApps::getPtr()':
> /home/jefix/study/qt/myapps/apps.cc:189: undefined reference to
> `LVIPtr::p_listviewitem'
> collect2: ld returned 1 exit status
> make: *** [apps] Error 1
> 
> what's the problem?
> thanks
> 
> 2007/5/7, Andreas Pakulat <apaku@xxxxxx>:
>> On 07.05.07 00:29:44, jiang jefix wrote:
>> > i define a static member in my code
>> > class LVIPtr
>> > {
>> > public :
>> >             static QPtrList<QListViewItem> p_listviewitem;
>> >             static void setupListviewPoint();
>> > //...........
>> > };
>> > void LVIPtr::setupListviewPoint()
>> > {
>> >             do something like  p_listviewitem.append ;
>> > }
>> >
>> > and in another class
>> > class myApps
>> > {
>> >        public:
>> >        void  getPtr();
>> > }
>> > void myApps::getPtr()
>> > {
>> >       QPtrList<QListViewItem> ptr=LVIPtr::p_listviewitem;
>> > //..........
>> > }
>> >
>> > gcc said:
>> > apps.o: In function
>> > `QPtrList<QListViewItem>::operator=(QPtrList<QListViewItem> const&)':
>> > /usr/lib/qt/include/qptrlist.h:72: undefined reference to
>> > `LVIPtr::p_listviewitem'
>>
>> This means that you don't link against the library in which LVIPtr is,
>> so just add that library via the .pro file that builds apps.o like this:
>>
>> LIBS += path-to-lib/libname.a
>>
>> If its a static lib. If you build a shared lib you'd need something like
>>
>> LIBS += -lname -Lpath-to-lib
>>
>> Andreas
>>
>> -- 
>> Good news.  Ten weeks from Friday will be a pretty good day.
>>
>> -- 
>> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
>> "unsubscribe" in the subject or the body.
>> List archive and information: http://lists.trolltech.com/qt-interest/
>>
>>
> 
> -- 
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> 

--
 [ signature omitted ] 

Message 5 in thread

I've attached a better example. Try compiling it with and without the
int foo_t::bar_ = 0;
line.

	Paul.

Paul Koshevoy wrote:
> This is a C++ error.
> 
> Static class member variables have to be instantiated/initialized outside of the
> class declaration. Example:
> 
> // declare the class in file foo.hxx
> class foo_t
> {
> public:
>   static int bar_;
> };
> 
> // initialize foo_t::bar_ in file foo.cxx
> int foo_t::bar_ = 0;
> 
> Hope this helps,
> 	Paul.
> 
> 
> jiang jefix wrote:
>> maybe i dont say clear
>> note that LVIPtr is a class i defined in my apps
>> it has a static member:
>> static QPtrList<QListViewItem> p_listviewitem;
>>
>> and in another class myApps:
>> i want to get p_listviewitem which is a static member defined in class
>> LVIPtr
>> class myApps
>> {
>>        void getPtr();
>> //........
>> };
>>
>> void myApps::getPtr()
>> {
>> QPtrList<QListViewItem> *ptr=LVIPtr::p_listviewitem;       // this is
>> line 189 in //apps.cc
>> //............
>> }
>>
>> and gcc said:
>> apps.o: In function `myApps::getPtr()':
>> /home/jefix/study/qt/myapps/apps.cc:189: undefined reference to
>> `LVIPtr::p_listviewitem'
>> collect2: ld returned 1 exit status
>> make: *** [apps] Error 1
>>
>> what's the problem?
>> thanks
>>
>> 2007/5/7, Andreas Pakulat <apaku@xxxxxx>:
>>> On 07.05.07 00:29:44, jiang jefix wrote:
>>>> i define a static member in my code
>>>> class LVIPtr
>>>> {
>>>> public :
>>>>             static QPtrList<QListViewItem> p_listviewitem;
>>>>             static void setupListviewPoint();
>>>> //...........
>>>> };
>>>> void LVIPtr::setupListviewPoint()
>>>> {
>>>>             do something like  p_listviewitem.append ;
>>>> }
>>>>
>>>> and in another class
>>>> class myApps
>>>> {
>>>>        public:
>>>>        void  getPtr();
>>>> }
>>>> void myApps::getPtr()
>>>> {
>>>>       QPtrList<QListViewItem> ptr=LVIPtr::p_listviewitem;
>>>> //..........
>>>> }
>>>>
>>>> gcc said:
>>>> apps.o: In function
>>>> `QPtrList<QListViewItem>::operator=(QPtrList<QListViewItem> const&)':
>>>> /usr/lib/qt/include/qptrlist.h:72: undefined reference to
>>>> `LVIPtr::p_listviewitem'
>>> This means that you don't link against the library in which LVIPtr is,
>>> so just add that library via the .pro file that builds apps.o like this:
>>>
>>> LIBS += path-to-lib/libname.a
>>>
>>> If its a static lib. If you build a shared lib you'd need something like
>>>
>>> LIBS += -lname -Lpath-to-lib
>>>
>>> Andreas
>>>
>>> -- 
>>> Good news.  Ten weeks from Friday will be a pretty good day.
>>>
>>> -- 
>>> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
>>> "unsubscribe" in the subject or the body.
>>> List archive and information: http://lists.trolltech.com/qt-interest/
>>>
>>>
>> -- 
>> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
>> "unsubscribe" in the subject or the body.
>> List archive and information: http://lists.trolltech.com/qt-interest/
>>
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> 

#include <iostream>
#include <iostream>

using std::cout;
using std::endl;

class foo_t
{
public:
  static int bar_;
};

// int foo_t::bar_ = 0;

int main()
{
  cout << foo_t::bar_ << endl;
  return 0;
}