C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 15th, 2004, 02:26 PM
blackeagle blackeagle is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 2 blackeagle User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 28 m 40 sec
Reputation Power: 0
Question 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

Reply With Quote
  #2  
Old December 18th, 2004, 01:16 PM
loopy123 loopy123 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 13 loopy123 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
sometimes pointer errors cannot be directly explained. Try using an array or refrence if you can.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > segmentation fault at runtime


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT