From 62aa3fb25ed211c3c204d0e534ebd68ef7cc615b Mon Sep 17 00:00:00 2001 From: mappu Date: Mon, 4 Nov 2024 23:02:50 +1300 Subject: [PATCH] qnetwork: add example --- .gitignore | 1 + examples/libraries/qt-network/main.go | 38 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 examples/libraries/qt-network/main.go diff --git a/.gitignore b/.gitignore index 3e161d60..60f627af 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ examples/mdoutliner/mdoutliner examples/windowsmanifest/windowsmanifest examples/uidesigner/uidesigner examples/libraries/extras-scintillaedit/extras-scintillaedit +examples/libraries/qt-network/qt-network examples/libraries/qt-printsupport/qt-printsupport examples/libraries/restricted-extras-qscintilla/restricted-extras-qscintilla diff --git a/examples/libraries/qt-network/main.go b/examples/libraries/qt-network/main.go new file mode 100644 index 00000000..60f3dd8e --- /dev/null +++ b/examples/libraries/qt-network/main.go @@ -0,0 +1,38 @@ +package main + +import ( + "log" + "os" + + "github.com/mappu/miqt/qt" + "github.com/mappu/miqt/qt/network" +) + +func main() { + + qt.NewQApplication(os.Args) + + log.Printf("Looking up DNS info, please wait...") + + dns := network.NewQDnsLookup2(network.QDnsLookup__A, "google.com") + dns.OnFinished(func() { + dns.DeleteLater() + + if dns.Error() != network.QDnsLookup__NoError { + log.Printf("An error occurred: %v", dns.ErrorString()) + return + } + + results := dns.HostAddressRecords() // CanonicalNameRecords, TextRecords, ServiceRecords, ... + log.Printf("Found %d result(s).", len(results)) + + for _, record := range results { + log.Printf("- %s", record.Value().ToString()) + } + + qt.QCoreApplication_Exit() + }) + dns.Lookup() + + qt.QApplication_Exec() +}