在Gtk2HS中创建一个ComboBox小部件 [英] Create a ComboBox widget in Gtk2HS
问题描述
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上使用文档。您链接的文档可能已过了十年。 从该文档,我们有 传递 或打开 I want to create a ComboBox widget with this code: But this error appears: 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 You are passing or turn on
这篇关于在Gtk2HS中创建一个ComboBox小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
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> void initGUI
window <- windowNew
...
cb <- comboBoxNewText
comboBoxAppendText cb "Option 1"
comboBoxAppendText cb "Option 2"
comboBoxSetActive cb 0
boxPackStart hb cb PackNatural 0
...
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;
.... }
type ComboBoxText = Text
comboBoxAppendText :: ComboBoxClass self => self -> ComboBoxText -> IO Int
"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 inimport qualified Data.Text as T
comboBoxAppendText cb (T.pack "Option 1")
OverloadedStrings
to have this automatically done for String
literals, as in:{-# LANGUAGE OverloadedStrings #-}
comboBoxAppendText cb "Option 1"