Re: [Dev-C++] segmentation fault at runtime
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2004-12-15 21:51:14
|
Are you sure that the beChannel object really have a valid pointer to your
beMDIWindow object.
Also, note that qDebug() which I don't know what it does might be
dangerous in case you have a multi-threaded application. Only the thread
that owns the MDI window should try and used any GDI objects.
/Per W
On Wed, 15 Dec 2004, Black Eagle wrote:
> 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
>
> #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
>
> And here is the beConsole.cpp
> // 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 any help !
>
>
> -------------------------------------------------------
> SF email is sponsored by - The IT Product Guide
> Read honest & candid reviews on hundreds of IT Products from real users.
> Discover which products truly live up to the hype. Start reading now.
> http://productguide.itmanagersjournal.com/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|