how use qt coding to read pc's network IP / internet IP address instead of 127.0.0.1?
how use qt coding to read pc's network IP / internet IP address instead of 127.0.0.1?
On Window OS....
Qt Code:
void Gui_FrontPage::TestQprocessqt4() { QProcess process; #if defined Q_WS_WIN if (!process.waitForFinished()) { msgb->information( this , "QT4 function test", process.errorString() ); } else { msgb->information( this , "QT4 function test", process.readAll() ); } #endif }To copy to clipboard, switch view to plain text mode
on linux only admin user can discovery
sudo ifconfig
wei243 (8th March 2007)
thx patrix08,
it is amazing - ur program show all the detail of ipconfig.
if i want to show ip address only, wat should i do?
first job .... split all line to a qstringlist....
register gateway or dns or network adress...
&& after .... http://www.regular-expressions.info/examples.html ...IP . && grep your
ip http://doc.trolltech.com/4.2/qregexp.html
similar to http://www.qtforum.de/forum/viewtopi...ighlight=regex
wei243 (9th March 2007)
i failed to try the QRegExp in reading the ip address from qprocess's return string.
actually i m a newbie n never seen QRegExp.
pls give me an example coding to read it.
thx
Google have so match QRegExp ip adress
on is.....
http://lists.trolltech.com/qt-intere...ad00085-0.html
search on http://www.koders.com/ you can find app piece and code trick ...
if you beginn on qt search qt function on http://www.koders.com/ && test it....
I learning qt 50% from http://www.koders.com/ && 30% from books and the rest from my php5 objekt know-how ....
My original work is cook chief 15 years a go.... and on 1999 i begin to write php & phython
untested code .....
Qt Code:
for (int i = 0; i < alline.size(); ++i) { if (onrow.contain("dns")) { /* list onrow.split(" "); */ qDebug() << "### onrow " << onrow; } } expression.setMinimal(true); int iPosition = 0; while( (iPosition = expression.indexIn( str , iPosition )) != -1 ) { qDebug() << "### grep " << grep; iPosition += expression.matchedLength(); }To copy to clipboard, switch view to plain text mode
&& on line 84 from http://qt-webdav.svn.sourceforge.net....h?view=markup
you find a sample wo find html image tag....
from my projekt
Last edited by patrik08; 9th March 2007 at 10:13.
wei243 (10th March 2007)
i manage to get ip now. thx alot.
With QT 4.2+ you can use QNetworkInterface:
Qt Code:
#include <QtDebug> qDebug() << addr.toString(); }To copy to clipboard, switch view to plain text mode
montylee (3rd November 2008)
Continuing this thread, how'd you do that on linux. Specifically, I need to retrieve gateway address on linux.
Regards,
The gateway address is not tied to an interface. Each system can have any number of gateways. You can run "route -n" and parse it to find the default gateway (one for 0.0.0.0 network) or do the same for /proc/net/route but that's probably everything that can be done (unless HAL exposes gateway definitions).
Gateway and network interface are two completely different things. For the latter see QNetworkInterface.
Thanks for the answer. I guess the simplest way is to use QProcess to run route -n command.
Regards
Bookmarks