# Cfunction: closures are not supported on this platform

**URL:** <https://discourse.julialang.org/t/cfunction-closures-are-not-supported-on-this-platform/126051>\
**Category:** General Usage\
**Created:** [February 19, 2025, 2:34am UTC](https://discourse.julialang.org/t/cfunction-closures-are-not-supported-on-this-platform/126051 "2025-02-19T02:34:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mpeters2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mpeters2/32/202247_2.png) [@mpeters2](https://discourse.julialang.org/u/mpeters2)\
**Post date:** [February 19, 2025, 2:34am UTC](https://discourse.julialang.org/t/cfunction-closures-are-not-supported-on-this-platform/126051/1 "2025-02-19T02:34:13Z")

</div>

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.

```julia
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

---

<div class="post-metadata">

**Author:** ![mpeters2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mpeters2/32/202247_2.png) [@mpeters2](https://discourse.julialang.org/u/mpeters2)\
**Post date:** [February 25, 2025, 12:29am UTC](https://discourse.julialang.org/t/cfunction-closures-are-not-supported-on-this-platform/126051/2 "2025-02-25T00:29:27Z")

</div>

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.

```julia
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)

```
