Static Lib mit QT
Verfasst: 27. November 2007 07:59
Hallo,
nachdem die Hilfe gestern mit dem Makefile so super funktioniert hat steh ich nun vor dem nächsten Problem.
Ich hab das Programm hier:
networkLib.h
networkLib.cpp
als static library erstellt:
networkLib.pro
Diese erstellt er mir auch ohne Fehlermeldung.
Wenn ich diese staticlib nun in ein anderes Programm einbinde, macht er an der stelle
einfach nichts. Er geht über den Code drüber und erzeugt keine Ausgaben.
Lasse ich mein networkLib aber als app erstellen und rufe da o.g. Konstruktor in der main auf geht alles ohne Probleme.
Headerdatei und staticlib haben den selben Namen, müsste also eigentlich alles klappen.
Kann es sein, dass irgendetwas nicht mit in die lib eingebunden wird und dann fehlt?
Gruß
Michael
nachdem die Hilfe gestern mit dem Makefile so super funktioniert hat steh ich nun vor dem nächsten Problem.
Ich hab das Programm hier:
networkLib.h
Code: Alles auswählen
#ifndef NETWORKLIB_H_
#define NETWORKLIB_H_
// --------------------------------------------------------
// Includes -
// --------------------------------------------------------
//#include "_tycs.h"
#include "inifile.h"
#include </usr/include/qt4/QtNetwork/QTcpSocket>
#include </usr/include/qt4/QtNetwork/QtNetwork>
// --------------------------------------------------------
// Class -
// --------------------------------------------------------
class MyNetwork : public QTcpSocket
{
Q_OBJECT
public:
QTcpSocket tcpSocket;
int nextBlockSize;
public:
MyNetwork();
public slots:
void tcpConnected();
void tcpDisconnected();
void tcpRead();
void tcpError();
};
#endif /*NETWORKLIB_H_*/
Code: Alles auswählen
// --------------------------------------------------------
// Includes -
// --------------------------------------------------------
#include "networkLib.h"
#include "inifile.h"
#include "typeDefs.h"
#include <iostream>
MyNetwork::MyNetwork()
{
connect ( &tcpSocket,
SIGNAL(connected()),
this,
SLOT(tcpConnected()));
connect ( &tcpSocket,
SIGNAL(disconnected()),
this,
SLOT(tcpDisconnected()));
connect ( &tcpSocket,
SIGNAL(readyRead()),
this,
SLOT(tcpRead()));
connect ( &tcpSocket,
SIGNAL(error(QAbstractSocket::SocketError)),
this,
SLOT(tcpError()));
tcpSocket.connectToHost("xxx", 21);
}
void MyNetwork::tcpConnected()
{
std::cout << "Connected successfully";
std::cout.flush();
}
void MyNetwork::tcpDisconnected()
{
std::cout << "Disconnected successfully";
std::cout.flush();
}
void MyNetwork::tcpRead()
{
std::cout << "Read\n";
std::cout.flush();
char buf[512];
int read_ret = 0;
if (tcpSocket.bytesAvailable() != 0)
{
read_ret = tcpSocket.read(buf, 512);
printf("received[%i] '%s'\n", read_ret, buf);
}
}
void MyNetwork::tcpError()
{
std::cout << "Error";
std::cout.flush();
}
networkLib.pro
Code: Alles auswählen
CONFIG += staticlib
TEMPLATE = lib
TARGET = networkLib
QT += core \
network
HEADERS += typeDefs.h \
networkLib.h \
inifile.h
SOURCES += networkLib.cpp \
inifile.cpp
FORMS +=
RESOURCES +=
Wenn ich diese staticlib nun in ein anderes Programm einbinde, macht er an der stelle
Code: Alles auswählen
MyNetwork *nw = new MyNetwork();
Lasse ich mein networkLib aber als app erstellen und rufe da o.g. Konstruktor in der main auf geht alles ohne Probleme.
Headerdatei und staticlib haben den selben Namen, müsste also eigentlich alles klappen.
Kann es sein, dass irgendetwas nicht mit in die lib eingebunden wird und dann fehlt?
Gruß
Michael