Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Taking member function pointer #55

Closed
ihnorton opened this issue Dec 27, 2014 · 11 comments
Closed

Taking member function pointer #55

ihnorton opened this issue Dec 27, 2014 · 11 comments

Comments

@ihnorton
Copy link
Contributor

To make the Qt example nicer, I tried this:
setup(hibtn, @cxx(&QPushButton::clicked))
which fails with:

cpp_ref: cxxref(CppAddr((CppNNS{(:QPushButton,:clicked)})()))
cxxref: CppAddr{CppNNS{(:QPushButton,:clicked)}}
:1:1: error: must explicitly qualify name of member function when taking its address
^
QAbstractButton::
ERROR: `juliatype` has no method matching juliatype(::CppPtr{CppValue{CppBaseType{symbol("clang::Type")},(false,false,false)},(false,false,false)})
while loading /home/isaiah/.julia/Cxx/test/qt1.jl, in expression starting on line 80

and this
setup(hibtn, pcpp"QPushButton::clicked"), which fails with:

jldev: /cmn/jldev/deps/llvm-svn/tools/clang/lib/Frontend/../../include/clang/AST/Type.h:562: const clang::ExtQualsTypeCommonBase* clang::QualType::getCommonPtr() const: Assertion `!isNull() && "Cannot retrieve a NULL type pointer"' failed.

signal (6): Aborted

Is there a way to do this that I am missing?

@Keno
Copy link
Collaborator

Keno commented Dec 27, 2014

The first way should work.

@maxruby
Copy link
Contributor

maxruby commented Dec 27, 2014

@ihnorton. FWIW, I think it works if you do the following:

# Passing a message to the Julia REPL (Fix)
# Create a function that prints a message in the REPL
say_hi() = println("Hi, this is fun!")::Void

. . . (same as before)

# Setup the button so that it is responsive to the click
cxx"""
   void setup(QPushButton* hibtn) 
   {
       QObject::connect(hibtn, &QPushButton::clicked, handle_hi);
   }
"""
@cxx setup(hibtn)

. . . (same as before)

# execute the app
@cxx app->exec()

Output

. . . last step
julia>  @cxx app->exec()        # click button "say hi" 
Hi, this is fun!

The current implementation in test/qttest.jlfreezes and does not seem to work, i.e., button is completely unresponsive. QMessageBoxwill remain unresponsive until you run @cxx app->exec().
(Note also you don´t need to add #include<iostream> in the cxx declaration of void handle_hi()).

@ihnorton
Copy link
Contributor Author

@maxruby thanks - the version currently on master does work for me. However, I'm trying to to write a generalized connect function which is able to take an arbitrary signal.

@maxruby
Copy link
Contributor

maxruby commented Dec 27, 2014

Sorry this was not helpful at all . . . I also have Cxx master and actually copied the code straight from Github to be 100% sure. Unfortunately, it hangs and I can not click the button at all.

@ihnorton
Copy link
Contributor Author

@maxruby no worries, it will be good to make sure it works on other plaforms (I'm on linux).

@Keno I thought it ought to work too. But the error is from bootstrap.cpp::createAddrOfExpr receiving the following expression (I added expr->dump() and res = CreateBuiltinUnaryOp...; res->dump())

input expression:

DeclRefExpr 0x6cdf4b0 'void (_Bool)' CXXMethod 0x6cb5180 'clicked' 'void (_Bool)'

result expression (after the error :1:1: error: must explicitly qualify name of member function when taking its address)

QAbstractButton::
UnaryOperator 0x1c4850d0 'void (class QAbstractButton::*)(_Bool)' prefix '&'
`-DeclRefExpr 0x1c485060 'void (_Bool)' CXXMethod 0x1c45adf0 'clicked' 'void (_Bool)'

Kind of confusing that the resulting expression does appear to be properly qualified despite the error message.

@Keno
Copy link
Collaborator

Keno commented Dec 27, 2014

I can take a look in a bit as soon as a I figure out #53, which I'm currently working on.

@maxruby
Copy link
Contributor

maxruby commented Dec 27, 2014

@ihnorton. OK. I will just use my own version of qttest.jl with a code that works for my system. If others have the same problem with OSX 10.9 or Mac in the future, at least they are informed in #57 (until it is fixed).

@ihnorton
Copy link
Contributor Author

@Keno the issue here appears to be (at least in part):

  • in bootstrap.cpp:CreateDeclRefExpr there is no qualifier in the resulting NestedNameSpecifierLoc from this call:
(gdb) f
#0  CreateDeclRefExpr (D=0x76ccbb0, builder=0x3971d40, islvalue=0) at ../src/bootstrap.cpp:832
832     clang::QualType T = D->getType();
(gdb) p builder->getWithLocInContext(*clang_astcontext)
$42 = {Qualifier = 0x0, Data = 0x0}

@Keno
Copy link
Collaborator

Keno commented Dec 29, 2014

Yes, I have reached the same conclusion. Patch on its way.

@Keno Keno closed this as completed in 6dd83d7 Dec 29, 2014
@ihnorton
Copy link
Contributor Author

The member reference error is definitely fixed, but now I get:

julia> x = @cxx(&QPushButton::clicked);
ERROR: `convert` has no method matching convert(::Type{CppPtr{CppValue{CppBaseType{symbol("clang::Type")},(false,false,false)},(false,false,false)}}, ::QualType)
Closest candidates are:
  convert(::Type{T}, ::T)
  convert(::Type{Nullable{T}}, ::T)

 in anonymous at ./REPL.jl

This doesn't seem like a display issue, because x is not defined afterward. Any suggestions where to look?

Keno added a commit that referenced this issue Dec 31, 2014
Keno added a commit that referenced this issue Dec 31, 2014
@Keno
Copy link
Collaborator

Keno commented Dec 31, 2014

Fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants