«FSharp, Qyoto on OS X

After playing around with MonoMac I realized most people I know are running windows, most of the time thats fine. But sometimes I'd like to show something off and Qyoto seems like it could be the perfect cross platform solution!

Warning, before I go on. I'm quite new to F# and Qt so if theres any errors give me a yell below

I got a bit stuck going through the whole process of setting everything up, so here's what I did for anyone else looking to play with it.

Compiling Mono

The mono packages for OS X are 32bit, where as the Qt libraries from homebrew are 64bit. So based on adamv's homebrew alt repo I made a mono3 recipe at aktowns/tappedbrews to install simply tap it and brew install.

brew tap aktowns/tappedbrews
brew install aktowns/tappedbrews/mono3

This will install mono 3.0.0 and FSharp 3.0.11 64bit, next we need Qt and Qyoto

Getting Qt and compiling Qyoto

If anyone knows how to imply --HEAD using depends_on in a recipe please tell me!
These homebrew recipes are mostly based off the instructions here with a few minor changes.

brew install qt
brew install aktowns/tappedbrews/smokegen --HEAD
brew install aktowns/tappedbrews/smokeqt --HEAD
brew install aktowns/tappedbrews/qyoto --HEAD

Installing monodevelop

Instead of compiling monodevelop, gtk# and numerous other dependencies its probably a lot easier to just grab the monodevelop binaries, install them and install mono 2.10.9 (to run monodevelop in) and select your default runtime as our brew compiled mono.

monodevelop

I noticed a bug with monodevelop (at least on 3.0.4.7) where if you have the binary 3.0.0 and your brew compiled 3.0.0 monodevelop wont let you set the default (it keeps defaulting to the binary 3.0.0) so for now 2.10.9 is fine.

Now lets create a new F# console project!

An example F# Qyoto Application

Adapted from zetcode's c# qyoto introduction

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
33: 
34: 
35: 
36: 
37: 
38: 
39: 
40: 
41: 
42: 
43: 
44: 
module Program

open System
open Qyoto

let SIGNAL = QWidget.SIGNAL
let SLOT = QWidget.SLOT

type QyotoApp() as self = class
  inherit QWidget()

  do
    base.WindowTitle <- "Hello World!"
    base.ToolTip <- "Goodbye World"

    self.setupButton
    self.resizeAndCenter 250 150

    base.Show()

  member self.resizeAndCenter w h =
    let qdw = new QDesktopWidget()
    let x = (qdw.Width - w) / 2
    let y = (qdw.Height - h) / 2
    base.Resize(w, h)
    base.Move(x, y)

  member self.setupButton : unit =
    let quit = new QPushButton("Quit", self)    
    self.Connect(quit, SIGNAL("clicked()"), SLOT("quit()")) |> ignore
    quit.SetGeometry(50, 40, 80, 30)

  // MARK: Slots
  [<Q_SLOT("quit()")>]
  member self.quit() : unit = Environment.Exit(0)
end

let main(args) : unit =    
    let application = new QApplication(args)
    let qyotoApp = new QyotoApp()

    QApplication.Exec() |> ignore

main(Environment.GetCommandLineArgs())
module Program
namespace System
val SIGNAL : obj

Full name: Program.SIGNAL
val SLOT : obj

Full name: Program.SLOT
Multiple items
type QyotoApp =
  inherit obj
  new : unit -> QyotoApp
  member setupButton : unit
  member quit : unit -> unit
  member resizeAndCenter : w:'a -> h:'b -> 'c

Full name: Program.QyotoApp

--------------------
new : unit -> QyotoApp
val self : QyotoApp
member QyotoApp.resizeAndCenter : w:'a -> h:'b -> 'c

Full name: Program.QyotoApp.resizeAndCenter
member QyotoApp.setupButton : unit

Full name: Program.QyotoApp.setupButton
type unit = Unit

Full name: Microsoft.FSharp.Core.unit
val ignore : value:'T -> unit

Full name: Microsoft.FSharp.Core.Operators.ignore
member QyotoApp.quit : unit -> unit

Full name: Program.QyotoApp.quit
type Environment =
  static member CommandLine : string
  static member CurrentDirectory : string with get, set
  static member CurrentManagedThreadId : int
  static member Exit : exitCode:int -> unit
  static member ExitCode : int with get, set
  static member ExpandEnvironmentVariables : name:string -> string
  static member FailFast : message:string -> unit + 1 overload
  static member GetCommandLineArgs : unit -> string[]
  static member GetEnvironmentVariable : variable:string -> string + 1 overload
  static member GetEnvironmentVariables : unit -> IDictionary + 1 overload
  ...
  nested type SpecialFolder
  nested type SpecialFolderOption

Full name: System.Environment
Environment.Exit(exitCode: int) : unit
val main : args:'a -> unit

Full name: Program.main
val args : 'a
val application : obj
val qyotoApp : QyotoApp
Environment.GetCommandLineArgs() : string []

hello world




comments powered by Disqus G+ Author linking