Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) WtGetIpAddress

 

WtQt CreatorLubuntu

 

Wt FAQ on how to obtain the client's (that is: any person that browser your Wt website from any place in the world) IP address.

 

Technical facts

 

Application type(s)

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ./CppWtGetIpAddress/CppWtGetIpAddress.pro

 

#-------------------------------------------------
#
# Project created by QtCreator 2011-05-15T20:17:39
#
#-------------------------------------------------
QT       += core
QT       -= gui
LIBS += -lwt -lwthttp -lboost_program_options
INCLUDEPATH += ../../Classes/CppWtAutoConfig
TARGET = CppWtGetIpAddress
CONFIG   += console
CONFIG   -= app_bundle
TEMPLATE = app
SOURCES += main.cpp \
    ../../Classes/CppWtAutoConfig/wtautoconfig.cpp
HEADERS += \
    ../../Classes/CppWtAutoConfig/wtautoconfig.h

 

 

 

 

 

./CppWtGetIpAddress/main.cpp

 

#include <Wt/WApplication>
#include <Wt/WEnvironment>
#include <Wt/WContainerWidget>
#include <Wt/WLabel>
//---------------------------------------------------------------------------
#include "wtautoconfig.h"
//---------------------------------------------------------------------------
const std::string GetIpAddress(const Wt::WEnvironment& env)
{
  return env.clientAddress();
}
//---------------------------------------------------------------------------
struct WtDialog : public Wt::WContainerWidget
{
  WtDialog(const std::string& ip_address)
  {
    new Wt::WLabel(
      std::string("Client IP address: ")
      + ip_address,this);
  }
};
//---------------------------------------------------------------------------
struct WtApplication : public Wt::WApplication
{
  WtApplication(const Wt::WEnvironment& env)
  : Wt::WApplication(env)
  {

    this->setTitle("CppWtGetIpAddress");
    this->useStyleSheet("wt.css");
    this->enableUpdates();
    const std::string ip_address = env.clientAddress();
    root()->addWidget(new WtDialog(ip_address));
  }
};
//---------------------------------------------------------------------------
Wt::WApplication * createApplication(const Wt::WEnvironment& env)
{
  return new WtApplication(env);
}
//---------------------------------------------------------------------------
int main(int argc, char **argv)
{
  WtAutoConfig a(argc,argv,createApplication);
  WtAutoConfig::SaveDefaultStylesheet();
  return a.Run();
}
//---------------------------------------------------------------------------

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml