Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the `itemDoubleClicked(QTreeWidgetItem*,int)` signal in qtHaskell

Tags:

haskell

qt

qt4

I want to use the itemDoubleClicked(QTreeWidgetItem*,int) signal in a Haskell program I'm writing where I am using qtHaskell for the GUI. To connect a function I have at other places done the following:

dummyWidget <- myQWidget
connectSlot object signal dummyWidget "customSlot()" $ f

Where object is some QWidget and signal is a string representing the signal, e.g. "triggered()", and f is the function I want to be called when the signale is send. The definition of connectSlot in the API is:

class Qcs x where
  connectSlot :: QObject a -> String -> QObject b -> String -> x -> IO ()

where the instances ofQcs are:

Qcs ()  
Qcs (QObject c -> String -> IO ())  
Qcs (QObject c -> Object d -> IO ())  
Qcs (QObject c -> Bool -> IO ())  
Qcs (QObject c -> Int -> IO ())  
Qcs (QObject c -> IO ())  
Qcs (QObject c -> OpenGLVersionFlag -> IO ())

The first Arguments passed is supposed to be the QObject of which I'm using a signal. As you can see, there is no instance where f, the function to connect to the signal, can have two further arguments to recieve the QWidget and the integer send by the signal. Is there a way to nevertheless connect that signal to a custom function?

like image 227
nano Avatar asked Jun 07 '10 16:06

nano


1 Answers

NOTE: I'm leaving this answer here only as documentation. My suggestion was based on a misunderstanding and doesn't actually work in this situation.


Would it work to call connectSlot with a partially applied custom function, as in the "Signals and Slots" example in the qtHaskell primer?

In that example the function on_hello_clicked has type QMessageBox () -> MyQPushButton -> IO (), which seems to correspond to what you want your f to look like, except that you want an additional Int argument at the end.

The authors use this function with connectSlot by first applying it to their message box:

hello <- myQPushButton "Hello qtHaskell World"
resize hello (200::Int, 60::Int)
mb <- qMessageBox hello 
connectSlot hello "clicked()" hello "click()" $ on_hello_clicked mb

So while on_hello_clicked doesn't have a type that's an instance of Qcs (since it wants both a message box and a button), the partially applied on_hello_clicked mb does.

like image 178
Travis Brown Avatar answered Nov 10 '22 07:11

Travis Brown