That's not a "problem", because:
QString::number(system("hostname -I"));
returns "0" (most likely because system("hostname -I")
command result is 0), so the QTextEdit
displays 0
.
Note that when you run a process:
- It returns an exit code (
main
function returned value) as integer. In mostly all cases 0 means it succeeded, anything else means it fails.
- It displays some information to standard output (what's sent to
std::cout
).
So, when you call system("hostname -I"))
it returns 0 if successfull and then you need to parse its standard output to find the IP address that was printed here.
You can catch the call's standard output by using QProcess
or by redirecting it to a file and then reading the file (system("hostname -I > ip.txt")
may work, to be tested)
Or, to get your IP address as text, the best is to use QNetworkInterface, check this post, then you can display it in your QTextEdit.