INTRODUCTION TO WEB DEVELOPMENT IN C++ WITH WT 4 - - PowerPoint PPT Presentation

introduction to web development in c with wt 4
SMART_READER_LITE
LIVE PREVIEW

INTRODUCTION TO WEB DEVELOPMENT IN C++ WITH WT 4 - - PowerPoint PPT Presentation

INTRODUCTION TO WEB DEVELOPMENT IN C++ WITH WT 4 https://www.webtoolkit.eu/wt Roel Standaert FOSDEM 2018 CONTENTS What is Wt? A simple Hello world Creating a larger application, with: Templates Style sheets i18n


slide-1
SLIDE 1

INTRODUCTION TO WEB DEVELOPMENT IN C++ WITH WT 4

Roel Standaert FOSDEM 2018 https://www.webtoolkit.eu/wt

slide-2
SLIDE 2

2 Introduction to web development in C++ with Wt 4

CONTENTS

  • What is Wt?
  • A simple “Hello world”
  • Creating a larger application, with:

– Templates – Style sheets – i18n

  • Being lazy effjcient with Bootstrap
  • Where to go from here?
slide-3
SLIDE 3

3 Introduction to web development in C++ with Wt 4

WHAT IS WT?

  • A server side web framework written in C++
  • Made for single page applications

– REST is possible, API currently verbose – Websites also possible: e.g. webtoolkit.eu

  • Inspired by Qt

widget based →

  • Abstraction of web technologies, adapts to what’s
  • available. No JavaScript required.
slide-4
SLIDE 4

4 Introduction to web development in C++ with Wt 4

WHY C++?

“I know we sometimes give C++ a bit of a bad rap for having funny defaults and weird, odd edge cases, but just take a look at JavaScript, really.”

– Matt Godbolt at CppCon 2017, youtu.be/bSkpMdDe4g4?t=2870

slide-5
SLIDE 5

5 Introduction to web development in C++ with Wt 4

WHY C++?

  • Low level vulnerabilities?

– XSS, CSRF and SQL injection are larger threats – Use best practices and tools (compiler warnings,

Valgrind, asan,...)

  • Small footprint: no garbage, no runtime, create small

statically linked binaries

  • Familiar to Qt developers
  • Ecosystem: Wt for web, any C or C++ library for

everything else

slide-6
SLIDE 6

6 Introduction to web development in C++ with Wt 4

WT 4

  • Released in September 2017
  • C++11: it’s about time
slide-7
SLIDE 7

7 Introduction to web development in C++ with Wt 4

HELLO WORLD!

Click "Greet me!" (or press Enter):

slide-8
SLIDE 8

8 Introduction to web development in C++ with Wt 4

HELLO WORLD!

# i n c l u d e < W t / W A p p l i c a t i

  • n

. h > # i n c l u d e < W t / W S e r v e r . h > i n t m a i n ( i n t a r g c , c h a r * a r g v [ ] ) { r e t u r n W t : : W R u n ( a r g c , a r g v , [ ] ( c

  • n

s t W t : : W E n v i r

  • n

m e n t & e n v ) { a u t

  • a

p p = s t d : : m a k e _ u n i q u e < W t : : W A p p l i c a t i

  • n

> ( e n v ) ; / / . . . r e t u r n a p p ; } ) ; }

  • WRun

un: creates WServer instance, and accepts connections

slide-9
SLIDE 9

9 Introduction to web development in C++ with Wt 4

HELLO WORLD!

# i n c l u d e < W t / W A p p l i c a t i

  • n

. h > # i n c l u d e < W t / W S e r v e r . h > i n t m a i n ( i n t a r g c , c h a r * a r g v [ ] ) { r e t u r n W t : : W R u n ( a r g c , a r g v , [ ] ( c

  • n

s t W t : : W E n v i r

  • n

m e n t & e n v ) { a u t

  • a

p p = s t d : : m a k e _ u n i q u e < W t : : W A p p l i c a t i

  • n

> ( e n v ) ; / / . . . r e t u r n a p p ; } ) ; }

  • WRun

un: creates WServer instance, and accepts connections

  • New connection

→ callback is called

slide-10
SLIDE 10

10 Introduction to web development in C++ with Wt 4

HELLO WORLD!

# i n c l u d e < W t / W A p p l i c a t i

  • n

. h > # i n c l u d e < W t / W S e r v e r . h > i n t m a i n ( i n t a r g c , c h a r * a r g v [ ] ) { r e t u r n W t : : W R u n ( a r g c , a r g v , [ ] ( c

  • n

s t W t : : W E n v i r

  • n

m e n t & e n v ) { a u t

  • a

p p = s t d : : m a k e _ u n i q u e < W t : : W A p p l i c a t i

  • n

> ( e n v ) ; / / . . . r e t u r n a p p ; } ) ; }

  • WRun

un: creates WServer instance, and accepts connections

  • New connection

callback is called →

  • WEnv

nviron

  • nment

nt describes “environment”, e.g. user agent information

slide-11
SLIDE 11

11 Introduction to web development in C++ with Wt 4

HELLO WORLD!

# i n c l u d e < W t / W A p p l i c a t i

  • n

. h > # i n c l u d e < W t / W S e r v e r . h > i n t m a i n ( i n t a r g c , c h a r * a r g v [ ] ) { r e t u r n W t : : W R u n ( a r g c , a r g v , [ ] ( c

  • n

s t W t : : W E n v i r

  • n

m e n t & e n v ) { a u t

  • a

p p = s t d : : m a k e _ u n i q u e < W t : : W A p p l i c a t i

  • n

> ( e n v ) ; / / . . . r e t u r n a p p ; } ) ; }

  • WRun

un: creates WServer instance, and accepts connections

  • New connection

callback is called →

  • WEnv

nviron

  • nment

nt describes “environment”, e.g. user agent information

  • Callback returns u

n i q u e _ p t r to WApp Applicat cation

  • n.
slide-12
SLIDE 12

12 Introduction to web development in C++ with Wt 4

HELLO WORLD!

# i n c l u d e < W t / W A p p l i c a t i

  • n

. h > # i n c l u d e < W t / W S e r v e r . h > i n t m a i n ( i n t a r g c , c h a r * a r g v [ ] ) { r e t u r n W t : : W R u n ( a r g c , a r g v , [ ] ( c

  • n

s t W t : : W E n v i r

  • n

m e n t & e n v ) { a u t

  • a

p p = s t d : : m a k e _ u n i q u e < W t : : W A p p l i c a t i

  • n

> ( e n v ) ; / / . . . r e t u r n a p p ; } ) ; }

  • WRun

un: creates WServer instance, and accepts connections

  • New connection

callback is called →

  • WEnv

nviron

  • nment

nt describes “environment”, e.g. user agent information

  • Callback returns u

n i q u e _ p t r to WApp Applicat cation

  • n.

→ One instance of WApplication per session

slide-13
SLIDE 13

13 Introduction to web development in C++ with Wt 4

HELLO WORLD! (CONTINUED)

a u t

  • a

p p = . . . a u t

  • r
  • t

= a p p

  • >

r

  • t

( ) ; / / W C

  • n

t a i n e r W i d g e t * r

  • t

( < d i v > )

slide-14
SLIDE 14

14 Introduction to web development in C++ with Wt 4

HELLO WORLD! (CONTINUED)

a u t

  • a

p p = . . . a u t

  • r
  • t

= a p p

  • >

r

  • t

( ) ; / / a d d a n e w W T e x t ( < s p a n > ) r

  • t
  • >

a d d W i d g e t ( s t d : : m a k e _ u n i q u e < W t : : W T e x t > ( " Y

  • u

r n a m e , p l e a s e ? " ) ) ;

slide-15
SLIDE 15

15 Introduction to web development in C++ with Wt 4

HELLO WORLD! (CONTINUED)

a u t

  • a

p p = . . . a u t

  • r
  • t

= a p p

  • >

r

  • t

( ) ; / / a d d a n e w W T e x t , u s i n g t h e a d d N e w s h

  • r

t h a n d r

  • t
  • >

a d d N e w < W t : : W T e x t > ( " Y

  • u

r n a m e , p l e a s e ? " ) ;

slide-16
SLIDE 16

16 Introduction to web development in C++ with Wt 4

HELLO WORLD! (CONTINUED)

a u t

  • a

p p = . . . a u t

  • r
  • t

= a p p

  • >

r

  • t

( ) ; r

  • t
  • >

a d d N e w < W t : : W T e x t > ( " Y

  • u

r n a m e , p l e a s e ? " ) ; / / a d d a W L i n e E d i t ( < i n p u t t y p e = " t e x t " > ) W t : : W L i n e E d i t * e d i t = r

  • t
  • >

a d d N e w < W t : : W L i n e E d i t > ( ) ;

slide-17
SLIDE 17

17 Introduction to web development in C++ with Wt 4

HELLO WORLD! (CONTINUED)

a u t

  • a

p p = . . . a u t

  • r
  • t

= a p p

  • >

r

  • t

( ) ; r

  • t
  • >

a d d N e w < W t : : W T e x t > ( " Y

  • u

r n a m e , p l e a s e ? " ) ; W t : : W L i n e E d i t * e d i t = r

  • t
  • >

a d d N e w < W t : : W L i n e E d i t > ( ) ; / / a d d a W P u s h B u t t

  • n

( < b u t t

  • n

> ) a u t

  • b

t n = r

  • t
  • >

a d d N e w < W t : : W P u s h B u t t

  • n

> ( " G r e e t m e ! " ) ;

slide-18
SLIDE 18

18 Introduction to web development in C++ with Wt 4

HELLO WORLD! (CONTINUED)

a u t

  • a

p p = . . . a u t

  • r
  • t

= a p p

  • >

r

  • t

( ) ; r

  • t
  • >

a d d N e w < W t : : W T e x t > ( " Y

  • u

r n a m e , p l e a s e ? " ) ; W t : : W L i n e E d i t * e d i t = r

  • t
  • >

a d d N e w < W t : : W L i n e E d i t > ( ) ; a u t

  • b

t n = r

  • t
  • >

a d d N e w < W t : : W P u s h B u t t

  • n

> ( " G r e e t m e ! " ) ; / / a d d a W B r e a k ( < b r > ) r

  • t
  • >

a d d N e w < W t : : W B r e a k > ( ) ;

slide-19
SLIDE 19

19 Introduction to web development in C++ with Wt 4

HELLO WORLD! (CONTINUED)

a u t

  • a

p p = . . . a u t

  • r
  • t

= a p p

  • >

r

  • t

( ) ; r

  • t
  • >

a d d N e w < W t : : W T e x t > ( " Y

  • u

r n a m e , p l e a s e ? " ) ; W t : : W L i n e E d i t * e d i t = r

  • t
  • >

a d d N e w < W t : : W L i n e E d i t > ( ) ; a u t

  • b

t n = r

  • t
  • >

a d d N e w < W t : : W P u s h B u t t

  • n

> ( " G r e e t m e ! " ) ; r

  • t
  • >

a d d N e w < W t : : W B r e a k > ( ) ; / / e m p t y W T e x t i n P l a i n f

  • r

m a t ( d e f a u l t i s f i l t e r e d X H T M L ) a u t

  • r

e s u l t = r

  • t
  • >

a d d N e w < W t : : W T e x t > ( ) ; r e s u l t

  • >

s e t T e x t F

  • r

m a t ( W t : : T e x t F

  • r

m a t : : P l a i n ) ;

slide-20
SLIDE 20

20 Introduction to web development in C++ with Wt 4

HELLO WORLD! (CONTINUED)

a u t

  • a

p p = . . . a u t

  • r
  • t

= a p p

  • >

r

  • t

( ) ; r

  • t
  • >

a d d N e w < W t : : W T e x t > ( " Y

  • u

r n a m e , p l e a s e ? " ) ; W t : : W L i n e E d i t * e d i t = r

  • t
  • >

a d d N e w < W t : : W L i n e E d i t > ( ) ; a u t

  • b

t n = r

  • t
  • >

a d d N e w < W t : : W P u s h B u t t

  • n

> ( " G r e e t m e ! " ) ; r

  • t
  • >

a d d N e w < W t : : W B r e a k > ( ) ; a u t

  • r

e s u l t = r

  • t
  • >

a d d N e w < W t : : W T e x t > ( ) ; r e s u l t

  • >

s e t T e x t F

  • r

m a t ( W t : : T e x t F

  • r

m a t : : P l a i n ) ; / / c r e a t e a l a m b d a f u n c t i

  • n

a u t

  • s

h

  • w

G r e e t i n g = [ e d i t , r e s u l t ] { r e s u l t

  • >

s e t T e x t ( W t : : W S t r i n g ( " H e l l

  • ,

{ 1 } ! " ) . a r g ( e d i t

  • >

t e x t ( ) ) ) ; } ;

slide-21
SLIDE 21

21 Introduction to web development in C++ with Wt 4

HELLO WORLD! (CONTINUED)

a u t

  • a

p p = . . . a u t

  • r
  • t

= a p p

  • >

r

  • t

( ) ; r

  • t
  • >

a d d N e w < W t : : W T e x t > ( " Y

  • u

r n a m e , p l e a s e ? " ) ; W t : : W L i n e E d i t * e d i t = r

  • t
  • >

a d d N e w < W t : : W L i n e E d i t > ( ) ; a u t

  • b

t n = r

  • t
  • >

a d d N e w < W t : : W P u s h B u t t

  • n

> ( " G r e e t m e ! " ) ; r

  • t
  • >

a d d N e w < W t : : W B r e a k > ( ) ; a u t

  • r

e s u l t = r

  • t
  • >

a d d N e w < W t : : W T e x t > ( ) ; r e s u l t

  • >

s e t T e x t F

  • r

m a t ( W t : : T e x t F

  • r

m a t : : P l a i n ) ; a u t

  • s

h

  • w

G r e e t i n g = [ e d i t , r e s u l t ] { r e s u l t

  • >

s e t T e x t ( W t : : W S t r i n g ( " H e l l

  • ,

{ 1 } ! " ) . a r g ( e d i t

  • >

t e x t ( ) ) ) ; } ; / / c

  • n

n e c t s i g n a l s e d i t

  • >

e n t e r P r e s s e d ( ) . c

  • n

n e c t ( s h

  • w

G r e e t i n g ) ; b t n

  • >

c l i c k e d ( ) . c

  • n

n e c t ( s h

  • w

G r e e t i n g ) ;

slide-22
SLIDE 22

22 Introduction to web development in C++ with Wt 4

HELLO WORLD! (FINAL CODE)

slide-23
SLIDE 23

23 Introduction to web development in C++ with Wt 4

BUILD AND RUN

Re Releas lease: e:

c + +

  • s

t d = c + + 1 4

  • O

3

  • D

N D E B U G

  • h

e l l

  • .

w t h e l l

  • .

c p p \

  • I

/ p a t h / t

  • /

w t / i n c l u d e

  • L

/ p a t h / t

  • /

w t / l i b \

  • l

w t

  • l

w t h t t p

Debug: g:

c + +

  • s

t d = c + + 1 4

  • O
  • g

3

  • h

e l l

  • .

w t h e l l

  • .

c p p \

  • I

/ p a t h / t

  • /

w t / i n c l u d e

  • L

/ p a t h / t

  • /

w t / l i b \

  • l

w t d

  • l

w t h t t p d

Ru Run:

. / h e l l

  • .

w t

  • d
  • c

r

  • t

.

  • h

t t p

  • l

i s t e n l

  • c

a l h

  • s

t : 8 8

  • -docroot: Where to serve static content from
  • -http-listen: host and port to listen on

(0.0.0.0 for any IPv4, [0::0] for any IPv6)

slide-24
SLIDE 24

24 Introduction to web development in C++ with Wt 4

DEMO

slide-25
SLIDE 25

25 Introduction to web development in C++ with Wt 4

CREATING LARGER WT APPLICATIONS

  • Classic: using layouts:

– WBoxLayout, WGridLayout, WBorderLayout

  • Using templates:

– HTML and CSS (if CSS isn’t your forte, there’s

Bootstrap)

slide-26
SLIDE 26

26 Introduction to web development in C++ with Wt 4

TYPICAL PROJECT STRUCTURE

m y

  • w

t

  • a

p p / a p p r

  • t

/ t e m p l a t e s . x m l s t r i n g s . x m l w t _ c

  • n

f i g . x m l d

  • c

r

  • t

/ s t y l e . c s s s t r i n g s _ n l . x m l

English strings Dutch strings Templates Wt confjguration CSS stylesheet Static web content Confjguration, templates, SQLite database, i18n,...

slide-27
SLIDE 27

27 Introduction to web development in C++ with Wt 4

TEMPLATE.XML

< ? x m l v e r s i

  • n

= " 1 . " e n c

  • d

i n g = " U T F

  • 8

" ? > < m e s s a g e s > < m e s s a g e i d = " t p l . t e m p l a t e " > $ { t r : s t r . p r

  • m

p t } $ { e d i t } $ { b t n } < b r / > $ { r e s u l t } < / m e s s a g e > < / m e s s a g e s >

$ { v a r i a b l e } $ { f u n c t i

  • n

: a r g s }

slide-28
SLIDE 28

28 Introduction to web development in C++ with Wt 4

TEMPLATE.XML

< ? x m l v e r s i

  • n

= " 1 . " e n c

  • d

i n g = " U T F

  • 8

" ? > < m e s s a g e s > < m e s s a g e i d = " t p l . t e m p l a t e " > $ { t r : s t r . p r

  • m

p t } $ { e d i t } $ { b t n } < b r / > $ { r e s u l t } < / m e s s a g e > < / m e s s a g e s >

$ { v a r i a b l e } $ { f u n c t i

  • n

: a r g s }

slide-29
SLIDE 29

29 Introduction to web development in C++ with Wt 4

STRINGS.XML

< ? x m l v e r s i

  • n

= " 1 . " e n c

  • d

i n g = " U T F

  • 8

" ? > < m e s s a g e s > < m e s s a g e i d = " s t r . p r

  • m

p t " > P l e a s e e n t e r y

  • u

r n a m e : < / m e s s a g e > < m e s s a g e i d = " s t r . g r e e t

  • m

e " > G r e e t m e < / m e s s a g e > < m e s s a g e i d = " s t r . r e s u l t " > H e l l

  • ,

{ 1 } ! < / m e s s a g e > < / m e s s a g e s > < ? x m l v e r s i

  • n

= " 1 . " e n c

  • d

i n g = " U T F

  • 8

" ? > < m e s s a g e s > < m e s s a g e i d = " s t r . p r

  • m

p t " > V

  • e

r j

  • u

w n a a m i n : < / m e s s a g e > < m e s s a g e i d = " s t r . g r e e t

  • m

e " > B e g r

  • e

t m e < / m e s s a g e > < m e s s a g e i d = " s t r . r e s u l t " > H a l l

  • ,

{ 1 } ! < / m e s s a g e > < / m e s s a g e s >

STRINGS_NL.XML

slide-30
SLIDE 30

30 Introduction to web development in C++ with Wt 4

STYLE.CSS

b

  • d

y { f

  • n

t

  • f

a m i l y : s a n s

  • s

e r i f ; }

slide-31
SLIDE 31

31 Introduction to web development in C++ with Wt 4

LOADING TEMPLATES, STRINGS & STYLESHEETS

/ / l

  • a

d a p p r

  • t

/ t e m p l a t e . x m l a p p

  • >

m e s s a g e R e s

  • u

r c e B u n d l e ( ) . u s e ( a p p

  • >

a p p R

  • t

( ) + " t e m p l a t e " ) ; / / l

  • a

d a p p r

  • t

/ s t r i n g s . x m l / / (

  • r

a p p r

  • t

/ s t r i n g s _ n l . x m l ) a p p

  • >

m e s s a g e R e s

  • u

r c e B u n d l e ( ) . u s e ( a p p

  • >

a p p R

  • t

( ) + " s t r i n g s " ) ; / / a d d s t y l e s h e e t a p p

  • >

u s e S t y l e S h e e t ( " s t y l e . c s s " ) ;

slide-32
SLIDE 32

32 Introduction to web development in C++ with Wt 4

HELLOTEMPLATE

c l a s s H e l l

  • T

e m p l a t e : p u b l i c W t : : W T e m p l a t e { p u b l i c : H e l l

  • T

e m p l a t e ( ) ; } ;

slide-33
SLIDE 33

33 Introduction to web development in C++ with Wt 4

HELLOTEMPLATE (CONTINUED)

H e l l

  • T

e m p l a t e : : H e l l

  • T

e m p l a t e ( ) : W T e m p l a t e { t r ( " t p l . t e m p l a t e " ) } { a d d F u n c t i

  • n

( " t r " , & W T e m p l a t e : : F u n c t i

  • n

s : : t r ) ; a u t

  • e

d i t = b i n d W i d g e t ( " e d i t " , s t d : : m a k e _ u n i q u e < W t : : W L i n e E d i t > ( ) ) ; a u t

  • b

t n = b i n d N e w < W t : : W P u s h B u t t

  • n

> ( " b t n " , t r ( " s t r . g r e e t

  • m

e " ) ) ; b i n d E m p t y ( " r e s u l t " ) ; a u t

  • s

h

  • w

G r e e t i n g = [ t h i s ] { a u t

  • e

d i t = r e s

  • l

v e < W t : : W L i n e E d i t * > ( " e d i t " ) ; b i n d S t r i n g ( " r e s u l t " , t r ( " s t r . r e s u l t " ) . a r g ( e d i t

  • >

t e x t ( ) ) , W t : : T e x t F

  • r

m a t : : P l a i n ) ; } ; e d i t

  • >

e n t e r P r e s s e d ( ) . c

  • n

n e c t ( s h

  • w

G r e e t i n g ) ; b t n

  • >

c l i c k e d ( ) . c

  • n

n e c t ( s h

  • w

G r e e t i n g ) ; }

slide-34
SLIDE 34

34 Introduction to web development in C++ with Wt 4

NEW MAIN

slide-35
SLIDE 35

35 Introduction to web development in C++ with Wt 4

BUILD AND RUN

Re Releas lease: e:

c + +

  • s

t d = c + + 1 4

  • O

3

  • D

N D E B U G

  • t

e m p l a t e . w t t e m p l a t e . c p p \

  • I

/ p a t h / t

  • /

w t / i n c l u d e

  • L

/ p a t h / t

  • /

w t / l i b \

  • l

w t

  • l

w t h t t p

Debug: g:

c + +

  • s

t d = c + + 1 4

  • O
  • g

3

  • t

e m p l a t e . w t t e m p l a t e . c p p \

  • I

/ p a t h / t

  • /

w t / i n c l u d e

  • L

/ p a t h / t

  • /

w t / l i b \

  • l

w t d

  • l

w t h t t p d

Ru Run:

. / t e m p l a t e . w t

  • a

p p r

  • t

a p p r

  • t
  • d
  • c

r

  • t

d

  • c

r

  • t

\

  • h

t t p

  • l

i s t e n l

  • c

a l h

  • s

t : 8 8

slide-36
SLIDE 36

36 Introduction to web development in C++ with Wt 4

DEMO

slide-37
SLIDE 37

37 Introduction to web development in C++ with Wt 4

USING BOOTSTRAP: BEING LAZY EFFICIENT

a u t

  • t

h e m e = s t d : : m a k e _ s h a r e d < W t : : W B

  • t

s t r a p T h e m e > ( ) ; t h e m e

  • >

s e t V e r s i

  • n

( W t : : B

  • t

s t r a p V e r s i

  • n

: : v 3 ) ; a p p

  • >

s e t T h e m e ( t h e m e ) ;

  • Includes Bootstrap CSS
  • Adds appropriate classes
  • Wt’s own widgets in Bootstrap style
slide-38
SLIDE 38

38 Introduction to web development in C++ with Wt 4

TEMPLATE.XML: FORM

< d i v c l a s s = " f

  • r

m

  • h
  • r

i z

  • n

t a l " > < d i v c l a s s = " f

  • r

m

  • g

r

  • u

p " > < l a b e l c l a s s = " c

  • l
  • m

d

  • 3

c

  • n

t r

  • l
  • l

a b e l " f

  • r

= " $ { i d : e d i t } " > $ { t r : s t r . p r

  • m

p t } < / l a b e l > < d i v c l a s s = " c

  • l
  • m

d

  • 6

" > $ { e d i t } < / d i v > < / d i v > < d i v c l a s s = " f

  • r

m

  • g

r

  • u

p " > < d i v c l a s s = " c

  • l
  • m

d

  • f

f s e t

  • 3

c

  • l
  • m

d

  • 6

" > $ { b t n c l a s s = " b t n

  • p

r i m a r y " } < / d i v > < / d i v > < / d i v >

slide-39
SLIDE 39

39 Introduction to web development in C++ with Wt 4

TEMPLATE.XML: RESULT

$ { < i f

  • r

e s u l t > } < d i v c l a s s = " r

  • w

" > < d i v c l a s s = " a l e r t a l e r t

  • i

n f

  • t

e x t

  • c

e n t e r c

  • l
  • m

d

  • f

f s e t

  • 1

c

  • l
  • m

d

  • 8

" > $ { r e s u l t } < / d i v > < / d i v > $ { < / i f

  • r

e s u l t > }

$ { < c

  • n

d i t i

  • n

> } $ { < / c

  • n

d i t i

  • n

> }

slide-40
SLIDE 40

40 Introduction to web development in C++ with Wt 4

HELLOTEMPLATE (CONTINUED)

H e l l

  • T

e m p l a t e : : H e l l

  • T

e m p l a t e ( ) : W T e m p l a t e { t r ( " t p l . t e m p l a t e " ) } { a d d F u n c t i

  • n

( " i d " , & W T e m p l a t e : : F u n c t i

  • n

s : : i d ) ; a d d F u n c t i

  • n

( " t r " , & W T e m p l a t e : : F u n c t i

  • n

s : : t r ) ; a u t

  • e

d i t = b i n d W i d g e t ( " e d i t " , s t d : : m a k e _ u n i q u e < W t : : W L i n e E d i t > ( ) ) ; a u t

  • b

t n = b i n d N e w < W t : : W P u s h B u t t

  • n

> ( " b t n " , t r ( " s t r . g r e e t

  • m

e " ) ) ; b i n d E m p t y ( " r e s u l t " ) ; a u t

  • s

h

  • w

G r e e t i n g = [ t h i s ] { a u t

  • e

d i t = r e s

  • l

v e < W t : : W L i n e E d i t * > ( " e d i t " ) ; s e t C

  • n

d i t i

  • n

( " i f

  • r

e s u l t " , t r u e ) ; b i n d S t r i n g ( " r e s u l t " , t r ( " s t r . r e s u l t " ) . a r g ( e d i t

  • >

t e x t ( ) ) , W t : : T e x t F

  • r

m a t : : P l a i n ) ; } ; e d i t

  • >

e n t e r P r e s s e d ( ) . c

  • n

n e c t ( s h

  • w

G r e e t i n g ) ; b t n

  • >

c l i c k e d ( ) . c

  • n

n e c t ( s h

  • w

G r e e t i n g ) ; }

slide-41
SLIDE 41

41 Introduction to web development in C++ with Wt 4

BUILD AND RUN

Re Releas lease: e:

c + +

  • s

t d = c + + 1 4

  • O

3

  • D

N D E B U G

  • b
  • t

s t r a p . w t b

  • t

s t r a p . c p p \

  • I

/ p a t h / t

  • /

w t / i n c l u d e

  • L

/ p a t h / t

  • /

w t / l i b \

  • l

w t

  • l

w t h t t p

Debug: g:

c + +

  • s

t d = c + + 1 4

  • O
  • g

3

  • b
  • t

s t r a p . w t b

  • t

s t r a p . c p p \

  • I

/ p a t h / t

  • /

w t / i n c l u d e

  • L

/ p a t h / t

  • /

w t / l i b \

  • l

w t d

  • l

w t h t t p d

Ru Run:

. / b

  • t

s t r a p . w t

  • a

p p r

  • t

a p p r

  • t
  • d
  • c

r

  • t

d

  • c

r

  • t

\

  • h

t t p

  • l

i s t e n l

  • c

a l h

  • s

t : 8 8 \

  • r

e s

  • u

r c e s

  • d

i r = / p a t h / t

  • /

w t / s h a r e / W t / r e s

  • u

r c e s

slide-42
SLIDE 42

42 Introduction to web development in C++ with Wt 4

DEMO

slide-43
SLIDE 43

43 Introduction to web development in C++ with Wt 4

WHERE TO GO FROM HERE?

  • Tutorials: https://webtoolkit.eu/wt/documentation

A hands-on introduction to Wt

A hands-on introduction to Wt::Dbo

Introduction to Wt::Auth

Library overview

  • Widget gallery: https://webtoolkit.eu/widgets
  • GitHub: https://github.com/emweb/wt
  • Examples: examples directory in Wt source tree
slide-44
SLIDE 44

44 Introduction to web development in C++ with Wt 4

THANK YOU!