Cfunction: closures are not supported on this platform

I’ve been helping out on a wrapper for QT6, and I’m having problems with callbacks. Specifically, I get an error stating that “cfunction: closures are not supported on this platform”, and from what I gather, this seems to be specific to Apple Arm chips.

function clickedClear(displayWidget)
    setText(displayWidget, "")		# clear the displayWidget’s text
    show(displayWidget)				# redraw the displayWidget
end


app = QApplication(String[])				# make the QApplication
window = QWidget()							# make the window
displayBox = QLineEdit("", window)			# make a QLineEdit and fill it with an empty string
clearBtn = QPushButton( "clear", window )	# make a QPushbutton label ‘clear’
cc() = clickedClear(displayBox)				# callback passing displayBox widget
clicked!(clearBtn, cc)						# set the callback for clearBtn

How can I rewrite this so that it is kosher? From what I understand, the problem is that displayWidget is not in the same scope as the clickedClear() function.

Julia 1.11
MacOS 14.4.1
Apple M1 pro MacBook

For the record, the code below fixes the problem.

The problem is with the LLVM implementation for Apple Silicon. As try as I might, I was not able to pass a Julia function to QT as a callback (click connect). The solution is to put everything in the global scope, which is ugly.

using QtWrapper
using Libdl

app2 = QApplication(String[])

wind2 = QWidget()
setGeometry(wind2, 100, 300, 259, 339 )	# QRect(100, 300, 259, 339)

displayBox2 = QLineEdit("",wind2)
setGeometry(displayBox2, 10, 10, 241, 50)

clearBtn = QPushButton( "clear", wind2 )
setGeometry(clearBtn, 10, 280, 120, 50)	
#----------	
function clickedClear2(placeholder)	# uses globals
	print("clicked on Clear!")
	setText(displayBox2, "")
	show(displayBox2)
end
#----------	
f = dlsym(QtWrapper.libqt_wrapper[], "button_connect_clicked")
ccall(f, Cvoid, (QtWrapper.Ptr{Nothing}, QtWrapper.Ptr{Nothing}), QtWrapper.ptr(clearBtn), @cfunction($clickedClear2, Cvoid, (Bool,)))
#clicked!(clearBtn, clickedClear2)	# ERROR: cfunction: closures are not supported on this platform

showWidget!(wind2)
exec!(app2)
1 Like