1.2. First Observations - Basic Function Types

Haskell statements of the type qSomeQtClassName followed by a tuple of parameters are calls to constructors of the class type SomeQtClassName. In this example there are two: qApplication () and qPushButton "Hello..." . Note that constructor instances that take no parameters still need an empty pair of parentheses to terminate the statement. This is not an option and the program will not compile if they are omitted. Constructors which only take one parameter can omit the parentheses since they are implied in standard Haskell syntax. Note that although qtHaskell programs generally begin with a parameterless qApplication () call, the program name and other program parameters are passed automatically to the Qt application.

Calls to Qt static functions take the form qSomeQtClassNameSomeStaticFunction followed by a tuple of parameters. There is one such call in this example: qApplicationExec (). As with constructors, parentheses are mandatory for parameterless methods.

Calls to nearly all non-static functions take the form (q)someNonStaticFunction followed by the name of the object whose method is being called, followed by a tuple of parameters. There are two such calls in this example: resize hello (200::Int, 60::Int) and qshow hello (). Note that literal numerical values must be explicitly typed in most qtHaskell calls and that parentheses are once again mandatory for parameterless methods. Also note that some calls to non-static methods require a leading "q" character.

Hence we can formulate a general rule for deriving qtHasekll function syntax from the Qt documentation:

Note that calls to non-static methods do not take an initial capital letter even if prefixed by "q".

Also note there are a few exceptions to the above rules. Qt Haskell functions which connect signals or slots, set handlers, or call explicit destructors are slightly different. Constructors of Qt data classes can take an "_nf" suffix if they are not to be automatically garbage collected. In fact both constructors and static methods can take an extra leading "q" character in some cases. These differences will be discussed in later chapters.