在Gtk2HS中创建一个ComboBox小部件 [英] Create a ComboBox widget in Gtk2HS

查看:134
本文介绍了在Gtk2HS中创建一个ComboBox小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  void initGUI 
window< - windowNew

...

cb< - comboBoxNewText
comboBoxAppendText cb选项1
comboBoxAppendText cb选项2
comboBoxSetActive cb 0
boxPackStart hb cb PackNatural 0

...

但是出现此错误:

 无法将类型'[Char]'
与'text-1.2.2.0: Data.Text.Internal.Text'
预期类型:ComboBoxText
实际类型:[Char]
在'comboBoxAppendText'的第二个参数中,即
'Secuencial'
在'do'块的标记中:comboBoxAppendText cbSecuencial
在表达式中:
do {void initGUI;
窗口< - windowNew;
set
window
[windowTitle:=A title,
windowDefaultWidth:= 1024,....];
vb < - vBoxNew False 7;
....}

我只是遵循本教程( http://www.muitovar.com/gtk2hs/chap4-2.html )并阅读docs( http://projects.haskell.org/gtk2hs/docs/gtk2hs-docs-0.9.12/Graphics-UI-Gtk-ModelView-ComboBox.html#v%3AcomboBoxInsertText



我该如何使它工作?

预先致谢。

解决方案

我建议在Hackage上使用文档。您链接的文档可能已过了十年。



从该文档,我们有

  type ComboBoxText = Text 
comboBoxAppendText :: ComboBoxClass self =>自我 - > ComboBoxText - > IO Int

传递选项1作为 ComboBoxText 参数。在香草Haskell中,这是一个 String 而不是 Text - 如错误所述。您可以 字符串,如

将合格的Data.Text导入为T 
comboBoxAppendText cb(T.packOption 1)

或打开 OverloadedStrings 以自动完成字符串文字,as in:

  { - #LANGUAGE OverloadedStrings# - } 
comboBoxAppendText cbOption 1
code>


I want to create a ComboBox widget with this code:

void initGUI
  window <- windowNew

  ...

  cb <- comboBoxNewText
  comboBoxAppendText cb "Option 1"
  comboBoxAppendText cb "Option 2"
  comboBoxSetActive cb 0
  boxPackStart hb cb PackNatural 0

  ...

But this error appears:

Couldn't match type ‘[Char]’
                   with ‘text-1.2.2.0:Data.Text.Internal.Text’
    Expected type: ComboBoxText
      Actual type: [Char]
    In the second argument of ‘comboBoxAppendText’, namely
      ‘"Secuencial"’
    In a stmt of a 'do' block: comboBoxAppendText cb "Secuencial"
    In the expression:
      do { void initGUI;
           window <- windowNew;
           set
             window
             [windowTitle := "A title",
              windowDefaultWidth := 1024, ....];
           vb <- vBoxNew False 7;
           .... }

I am just following this tutorial (http://www.muitovar.com/gtk2hs/chap4-2.html) and reading the docs (http://projects.haskell.org/gtk2hs/docs/gtk2hs-docs-0.9.12/Graphics-UI-Gtk-ModelView-ComboBox.html#v%3AcomboBoxInsertText)

How can i make it work?

Thanks in advance.

解决方案

I recommend using the documentation on Hackage. The documentation you linked is probably a decade stale by now.

From that documentation, we have

type ComboBoxText = Text
comboBoxAppendText :: ComboBoxClass self => self -> ComboBoxText -> IO Int

You are passing "Option 1" as the ComboBoxText argument. In vanilla Haskell, this is a String rather than a Text -- as the error says. You can either pack the String, as in

import qualified Data.Text as T
comboBoxAppendText cb (T.pack "Option 1")

or turn on OverloadedStrings to have this automatically done for String literals, as in:

{-# LANGUAGE OverloadedStrings #-}
comboBoxAppendText cb "Option 1"

这篇关于在Gtk2HS中创建一个ComboBox小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆