View Full Version : Hostlookup using QHostInfo

21st January 2010, 18:17

I have the following code to perform a host lookup

// Perform host lookup
m_DoLookup = true;
m_Lookupid = QHostInfo::lookupHost( Address, this, SLOT( SLOTGetHostIPAddress(QHostInfo)) );

// Start short lookup timeout
m_LookupTimer = new QTimer(this);
connect(m_LookupTimer, SIGNAL(timeout()), this, SLOT(SLOTLookupTimeout()));

// Wait for lookup timeout to complete
while( m_DoLookup )

The timeout slot is

void SLOTLookupTimeout()
// abort host lookup
QHostInfo::abortHostLookup( m_Lookupid );

Now when the QHostInfo::abortHostLookup() is called, I am expecting it to then go into my SLOTGetHostIPAddress(), where I can check for the failure. However, it never goes in there, and always stays in my processEvents() while loop. Any thoughts why?

I have confirmed the id returned from QHostInfo::lookupHost() is the same as the one passed into QHostInfo::abortHostLookup(). Is it just the case that if i abort a lookup, i don't get anything back saying it has been aborted?


21st January 2010, 18:37
I have also noticed that with the

QHostInfo::abortHostLookup( m_Lookupid );


m_Lookupid = QHostInfo::lookupHost( Address, this, SLOT( SLOTGetHostIPAddress(QHostInfo)) );

calls in my code, my application crashes on exit, whether the lookup completed or not. Not sure why this is yet, will try looking at this.


22nd January 2010, 11:13
Still non the wiser about what is causing the crash in my application. Calling the static blocking call,

QHostInfo fromName ( const QString & name )

To resolve the host name to ip address does not cause my application to crash, but any call to the static calls

lookupHost ( const QString & name, QObject * receiver, const char * member )


abortHostLookup ( int id )

Causes my application to have an access violtation in qt_call_post_routines(), which is called from the QApplication destructor. Anyone have any ideas why?


22nd January 2010, 14:55
In which Qt version do you have the crash?

SLOTGetHostIPAddress won't be called if you abort.

22nd January 2010, 17:46
The crash is in QT 4.5.2.

I came to the conclusion this might be a QT issue, and am currently in the process of installing QT 4.6.1 on my system.

22nd January 2010, 17:48
Also, this is on Windows XP.

23rd January 2010, 17:43
Please report back and tell if it fixes the issue.

26th January 2010, 14:58
Good news. Upgrading to QT 4.6.1 has resolved the crash on exit of my applciation :)