tags:

views:

277

answers:

1

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?

+1  A: 

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.

Travis Brown
Yes, I have been doing this on other places, but at this point I do not think it would solve my problem, since the partially applied function would be the 5. argument of `connectSlot` and I still would not be able to get both the `QWidgetItem` and the integer as arguments for my function, which would tell me what item in a list was clicked. By the way, just getting the `QWidgetItem` and disregarding the integer does not seem to work either.
nano