You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

Membit

Beginner

  • "Membit" is male
  • "Membit" started this thread

Posts: 20

Location: Finland

  • Send private message

1

Thursday, February 18th 2010, 9:22am

problem enumerating objects, building Chat application.

Hi guys!

I'm trying to build a Chat application with Qt and TCP. I've attached the server-side project as an attachment.
Each new client is created as an object on ClientSocket-class.

Each client should be able to write messages to other clients, of course, so I was thinking of creating a static vector where to store all the chatters. However as you see if you try to build my project enumerating the objects from the vector doesn't work. I've tried to do it according to this example:
http://www.cplusplus.com/reference/stl/vector/begin/

QtCreator outputs following error while build:

Source code

1
2
clientsocket.cpp:54: error: no match for 'operator=' in 'i = ClientSocket::_usrList.std::vector<_Tp, _Alloc>::begin [with _Tp = ClientSocket, _Alloc = std::allocator<ClientSocket>]()'
clientsocket.cpp:54: error: no match for 'operator<' in 'i < ClientSocket::_usrList.std::vector<_Tp, _Alloc>::end [with _Tp = ClientSocket, _Alloc = std::allocator<ClientSocket>]()'



What am I doing wrong? 8|

Thanks already!
-Membit
Membit has attached the following file:

Membit

Beginner

  • "Membit" is male
  • "Membit" started this thread

Posts: 20

Location: Finland

  • Send private message

2

Thursday, February 18th 2010, 11:21am

OK I solved the problem that I had at first place. I faced another wall:

error messages:

Source code

1
2
3
4
5
6
7
clientsocket.cpp:7: undefined reference to `ClientSocket::_usrList'
clientsocket.cpp:7: undefined reference to `ClientSocket::_usrList'
clientsocket.cpp:54: undefined reference to `ClientSocket::_usrList'
clientsocket.cpp:54: undefined reference to `ClientSocket::_usrList'
clientsocket.cpp:88: undefined reference to `ClientSocket::_usrList'
clientsocket.cpp:88: more undefined references to `ClientSocket::_usrList' follow
:-1: error: collect2: ld returned 1 exit status


If I take the static definition away from _usrList, build goes OK, but then of course the program don't work as I wanted.
Membit has attached the following file:

3

Thursday, February 18th 2010, 4:33pm

in ClientSocket class declaration

Source code

1
2
3
4
5
6
7
class ClientSocket : 
    public QTcpSocket
{
    // ...
    static std::vector<ClientSocket*> _usrList; // ClientSocket::_usrList declaration
    // ...
};

in ClientSocket class definition

Source code

1
2
3
4
5
ClientSocket::ClientSocket( QObject * parent ) : 
    QTcpSocket( parent )
{
    _usrList.push_back( this ); // ClientSocket::_usrList usage
}

but ClientSocket::_usrList is never defined

Membit

Beginner

  • "Membit" is male
  • "Membit" started this thread

Posts: 20

Location: Finland

  • Send private message

4

Thursday, March 25th 2010, 8:34am

Hello,

I still don't know how to get rid of my problem. I have modified the code just a little, by changing std::vector to QVector, and some minor stuff, but I still face the same problem.

I think I could be able to go around my problem by using a global QVector where to store all the clientsockets, but I don't want to.
How do I need to define _usrList in the ClientSocket class to be able to use it?
Membit has attached the following file: