[solved] verwenden von QNativeSocketEngine

Alles rund um die Programmierung mit Qt
Antworten
uhu01
Beiträge: 150
Registriert: 10. Juli 2005 20:46

[solved] verwenden von QNativeSocketEngine

Beitrag von uhu01 »

Hy!

Ich habe ein blödes Problem: Da ich einen blockierenden Socket benötige habe ich mir mal angeschaut wie Qt die OS-Funktionen abstrahiert. Dabei binn ich auf die QNativeSocketEngine gestossen. Diese habe ich nun auch in mein Programm eingebaut, das Problem ist jedoch das ich einen Linker Fehler erhalte wenn ich mein Programm compiliere:

Code: Alles auswählen

controller error LNK2019: unresolved external symbol "public: __thiscall QNativeSocketEngine::QNativeSocketEngine(class QObject *)" (??0QNativeSocketEngine@@QAE@PAVQObject@@@Z) referenced in function "public: __thiscall CAN::TCPConnector::TCPConnector(void)" (??0TCPConnector@CAN@@QAE@XZ)
controller error LNK2019: unresolved external symbol "public: enum QAbstractSocket::SocketState __thiscall QAbstractSocketEngine::state(void)const " (?state@QAbstractSocketEngine@@QBE?AW4SocketState@QAbstractSocket@@XZ) referenced in function "public: __thiscall CAN::TCPConnector::~TCPConnector(void)" (??1TCPConnector@CAN@@QAE@XZ)
Ich weis das die Klasse nicht "offiziell" zur Qt gehört, deswegen auch für alle die's interessiert unten dran die Doku.

Nun zu meiner Frage: Hat diese Klasse schon mal jemand von euch benutzt? Bzw. hat jemand eine Idee warum die Linker Fehler kommen, obwohl beide Funktionen im Source vorhanden sind? Vor allem sind dies die einzigen Fehler die ich wegen dem benutzen von QNativeSocketEngine bekomme, die restlichen Memberfunktionen (read, write, connect...) sind kein Problem. Die Netzwerklibrarys linke ich übrigens mit.

mfg
uhu01

Code: Alles auswählen

    QtSocketLayer provides basic socket functionality provided by the
    operating system. It also keeps track of what state the socket is
    in, and which errors that occur.

    The classes QTcpSocket, QUdpSocket and QTcpServer provide a
    higher level API, and are in general more useful for the common
    application.

    There are two main ways of initializing the a QNativeSocketEngine; either
    create a new socket by passing the socket type (TcpSocket or
    UdpSocket) and network layer protocol (IPv4Protocol or
    IPv6Protocol) to initialize(), or pass an existing socket
    descriptor and have QNativeSocketEngine determine the type and protocol
    itself. The native socket descriptor can later be fetched by
    calling socketDescriptor(). The socket is made non-blocking, but
    blocking behavior can still be achieved by calling waitForRead()
    and waitForWrite(). isValid() can be called to check if the socket
    has been successfully initialized and is ready to use.

    To connect to a host, determine its address and pass this and the
    port number to connectToHost(). The socket can then be used as a
    TCP or UDP client. Otherwise; bind(), listen() and accept() are
    used to have the socket function as a TCP or UDP server. Call
    close() to close the socket.

	bytesAvailable() is called to determine how much data is available
	for reading. read() and write() are used by both TCP and UDP
	clients to exchange data with the connected peer. UDP clients can
	also call hasMoreDatagrams(), nextDatagramSize(),
	readDatagram(), and writeDatagram().

    Call state() to determine the state of the socket, for
    example, ListeningState or ConnectedState. socketType() tells
    whether the socket is a TCP socket or a UDP socket, or if the
    socket type is unknown. protocol() is used to determine the
    socket's network layer protocol.

    localAddress(), localPort() are called to find the address and
    port that are currently bound to the socket. If the socket is
    connected, peerAddress() and peerPort() determine the address and
    port of the connected peer.

    Finally, if any function should fail, error() and
    errorString() can be called to determine the cause of the error.
Zuletzt geändert von uhu01 am 6. Januar 2007 17:21, insgesamt 1-mal geändert.
Christian81
Beiträge: 7319
Registriert: 26. August 2004 14:11
Wohnort: Bremen
Kontaktdaten:

Beitrag von Christian81 »

Da es eine private Klasse ist, wird sie auch nicht exportiert. Deshalb kann der Linker auch nicht darauf zugreifen.
MfG Christian

'Funktioniert nicht' ist keine Fehlerbeschreibung
uhu01
Beiträge: 150
Registriert: 10. Juli 2005 20:46

Beitrag von uhu01 »

Hy!

Wie kommt es das der Linker die restlichen Funktionen findet?
Gibt es eine möglichkeit die Klasse trotzdem zu benutzen?

Edit: Oder kennt jemand von euch eine Library die Sockets auf derselben Ebene abstrahiert? (also so gut wie gar nicht, nur Platformunabhängig) Die Library müsste auf Linux und Windows funktionieren.

mfg
uhu01
uhu01
Beiträge: 150
Registriert: 10. Juli 2005 20:46

Beitrag von uhu01 »

Hy!

Für alle die auch mal sowas brauchen, hier hab ich eine kleine API gefunden die nichts anders macht als die normalen Socket Funktionen aufzurufen, sie berücksichtigt allerdings die Unterschiede zwischen Windows und Linux Sockets.

http://cs.ecs.baylor.edu/~donahoo/pract ... practical/

mfg
uhu01
Antworten