|
From: | Alex Leach |
Subject: | QtHandles in a C++ application with embedded interpreter |
Date: | Fri, 16 Oct 2020 09:53:19 +0000 |
Hello,
I'm trying to build what I thought would be a fairly simple Qt Application, that calls a few .M script files. When running these scripts through the Octave GUI, figures are shown with the lovely QtHandles backend. However, I'm struggling to get figures to plot
using the Qt Handles backend using my own app.
After realising that the Octave GUI is built with Qt, I thought it would be simple to write a Qt app that has an embedded interpreter. As my app is built with Qt in C++, the Qt core libraries are all linked in, I'm also linking to -loctave -loctinterp -loctgui.
Is it possible then, to get figures to display using QtHandles in my app?
I have created a MyApplication class, that subclasses both QApplication and octave::application. This therefore has a pointer to an Octave interpreter, m_interpreter, with which I can run `m_interpreter->eval_string` or `octave::feval` to run code that's shipped
with my app.
The last thing I've tried, is to run `m_interpreter->eval_string('__init_qt__', false, status)`, but this doesn't provide any output on the terminal and if I then list the available toolkits (I have a method printBackends, below), it only shows 'fltk' and 'gnuplot'.
The qt backend is still not available. I've got a registerBackends method as well (see below), but this approach doesn't seem to work, causing seg-faults later on.
I've looked at the code in __init_qt__.cc, but without copying everything from libgui/graphics and building that with my app, I'm not sure how I can call into it? The headers aren't distributed with pre-built binaries, and I get linker errors if I try and call
`F__init_qt__`, after defining it as per the DEFMETHOD_DLD(__init_qt__) macro:-
`extern octave_value_list
F__init_qt__
(octave::interpreter&
interp,
const octave_value_list& args, int nargout); `
Does anyone have any pointers how I can use QtHandles in my C++ app?
Thanks and kind regards,
Alex
void MyApplication::printBackends(void)
{
Cell available_toolkits = m_interpreter->get_gtk_manager().available_toolkits_list(); octave_value val; std::cerr << "Have " << available_toolkits.numel() << " toolkits available." << std::endl; for (octave_idx_type i = 0; i < available_toolkits.numel() ; i++ ) { val = available_toolkits(i); std::cerr << "Available Toolkit: " << available_toolkits(i).string_value() << std::endl; }
}
void MyApplication::registerBackends(void)
{
std::cerr << "Registering Qt Graphics" << std::endl; base_graphics_toolkit base_qttk = base_graphics_toolkit(std::string("qt")); graphics_toolkit qttk = graphics_toolkit(&base_qttk); m_interpreter->get_gtk_manager().load_toolkit(qttk); m_interpreter->get_gtk_manager().register_toolkit("qt"); std::cerr << "Graphics registered" << std::endl; } |
[Prev in Thread] | Current Thread | [Next in Thread] |