
December 15th, 2004, 02:26 PM
|
|
Registered User
|
|
Join Date: Dec 2004
Posts: 2
Time spent in forums: 28 m 40 sec
Reputation Power: 0
|
|
segmentation fault at runtime
Hi guys!
I got a problem at run time, when using a pointer in a function.
The error is in the function KviIrcServer* server() at line : return m_pSrv;
In all other functions I got no problem with this variable. It is another class that tries to call this function, it's the friendclass beChannel
Here is the beConsole.h
Code:
#ifndef BE_CONSOLE_H
#define BE_CONSOLE_H
#include "beMDIWindow.h"
class KviIrcServer;
class beConsole : beMDIWindow
{
friend class beIRC;
friend class beChannel;
Q_OBJECT
public :
beConsole(QWidget * parent = 0, const char * name = 0, WFlags f = 0);
~beConsole();
KviIrcServer* server();
protected :
bool connectToServer();
private slots :
virtual void hostFound();
virtual void connected();
virtual void socketReadyRead();
virtual void disconnected();
void send(const QString & command);
private :
KviIrcServer * m_pSrv;
// KviProxy * prx;
QSocket * m_pQSocket;
};
#endif
Here is the beConsole.cpp source
Code:
// beIRC stuff
#include "beConsole.h"
// kvirc stuff
#define HAVE_CONFIG_H
#include "config.h"
#include <kvirc/3.0.1/kvi_app.h>
#include <kvirc/3.0.1/kvi_ircserverdb.h>
#include <kvirc/3.0.1/kvi_confignames.h>
// QT Stuff
#include <qregexp.h>
#include <qsocket.h>
extern KVIRC_API KviIrcServerDataBase * g_pIrcServerDataBase;
beConsole::beConsole(QWidget * parent,const char * name, WFlags f) : beMDIWindow(parent,name,f)
{
m_windowType = beMDIWindow::Console;
KviIrcNetwork * net = g_pIrcServerDataBase->currentNetwork();
if(net)m_pSrv = net->currentServer();
QString srvname = m_pSrv->hostname();
setCaption(srvname);
connect ( this, SIGNAL( userInput(const QString &) ), this, SLOT ( send(const QString &) ) );
}
beConsole::~beConsole()
{
delete m_pSrv;
}
bool beConsole::connectToServer()
{
if(!m_pSrv) { return false; }
// QString text = "Connect to server";
// m_pLineView->addLine(text);
// \n for new liens
// \t for tabs
append("<mytag>Connecting to server...</mytag>");
m_pQSocket = new QSocket(this);
connect( m_pQSocket, SIGNAL( hostFound() ), this, SLOT( hostFound() ) );
connect( m_pQSocket, SIGNAL( connected() ), this, SLOT( connected() ) );
connect( m_pQSocket, SIGNAL( readyRead() ), this, SLOT(socketReadyRead()) );
connect( m_pQSocket, SIGNAL( connectionClosed() ), this, SLOT( disconnected() ));
m_pQSocket->connectToHost( m_pSrv->hostname(), m_pSrv->port() );
return true;
}
void beConsole::hostFound()
{
append("<mytag>Host found ...</mytag>");
}
void beConsole::connected()
{
append("<mytag>Connected to "+m_pSrv->hostname()+"</mytag>");
QString cmd;
cmd = "USER alex 0 "+m_pSrv->hostname()+" :Using beIRC 0.0.1\n";
m_pQSocket->writeBlock( cmd.latin1(), cmd.length() );
cmd = "NICK blackeagle654\n";
m_pQSocket->writeBlock( cmd.latin1(), cmd.length() );
}
void beConsole::socketReadyRead()
{
// append("<mytag>Socket is ready to read</mytag>");
while ( m_pQSocket->canReadLine() ) {
QString msg = m_pQSocket->readLine();
QRegExp rxA("(.*)\n$");
rxA.search( msg );
append( rxA.cap(1) );
/* BEGIN ping pong fast reply */
QRegExp rx("^PING :([0-9]+)");
int pos;
if( (pos = rx.search(msg)) != -1)
{
QString cmd = "PONG :"+rx.cap(1)+"\n";
m_pQSocket->writeBlock( cmd.latin1(), cmd.length() );
}
/* END ping pong fast reply */
QRegExp rx2("376.*End of /MOTD command");
if( (pos = rx2.search(msg)) != -1)
{
QString cmd = "JOIN #gentoo\n";
m_pQSocket->writeBlock( cmd.latin1(), cmd.length() );
}
}
}
void beConsole::disconnected()
{
append("<mytag>Disconnected from server</mytag>");
}
void beConsole::send(const QString & command)
{
append("<command>"+command+"</command>");
// command.append("\n");
QString tmp = command+"\n";
m_pQSocket->writeBlock( tmp.latin1(), tmp.length() );
}
KviIrcServer* beConsole::server()
{
qDebug("returning server");
return m_pSrv;
}
Thanks for help
|