I am trying to run a Octave standalone program which display a GUI, but the error that I get is:
$ ./test1
terminate called after throwing an instance of 'octave::execution_exception'
what(): graphics_toolkit: qt toolkit is not available
Aborted (core dumped)
The C++ program called /path-to-test-gui/test1.cc that I use:
#include <iostream>
#include <unistd.h>
#include <octave/oct.h>
#include <octave/octave.h>
#include <octave/parse.h>
#include <octave/interpreter.h>
#include <octave/graphics-toolkit.h>
int
main (void)
{
octave::cmdline_options cmdline_option;
octave::graphics_toolkit graphics_toolkit ("qt");
octave::interpreter interpreter;
try
{
int status = interpreter.execute ();
if (status != 0)
{
std::cerr << "creating embedded Octave interpreter failed!"
<< std::endl;
return status;
}
octave::source_file ("runApp.m");
octave_value_list out = octave::feval ("runApp");
if (out.length () < 1)
std::cout << "invalid\n";
}
catch (const octave::exit_exception& ex)
{
std::cerr << "Octave interpreter exited with status = "
<< ex.exit_status () << std::endl;
}
//catch (const octave::execution_exception&)
// {
// std::cerr << "error encountered in Octave evaluator!" << std::endl;
// }
return 0;
}
The /path-to-test-gui/runApp.m file is in the same directory that test1.cc:
function ret = runApp()
[dir, name, ext] = fileparts( mfilename('fullpathext') );
global _wkbBasePath = dir;
global _wkbImgPath = [dir filesep() 'img'];
addpath([dir filesep() "libs" ]);
addpath([dir filesep() "fcn" ]);
addpath([dir filesep() "wnd" ]);
waitfor(main().figure);
end
If I run from Octave CLI o GUI the runApp.m file, the GUI development is display without errors. But if is disable (octave-cli runApp.m
) the GUI the error is the same
On /path-to-test-gui/wnd/ directory I have six m-files:
/path-to-test-gui/wnd/main.m
function wnd = main()
main_def;
wnd = show_main();
end
/path-to-test-gui/wnd/main_def.m
## -*- texinfo -*-
## @deftypefn {} {} dummy()
##
## This is a dummy function documentation. This file have a lot functions
## and each one have a little documentation. This text is to avoid a warning when
## install this file as part of package.
## @end deftypefn
##
## Set the graphics toolkit and force read this file as script file (not a function file).
##
graphics_toolkit qt;
##
##
##
## Begin callbacks definitions
##
## @deftypefn {} {} Button_5_doIt (@var{src}, @var{data}, @var{main})
##
## Define a callback for default action of Button_5 control.
##
## @end deftypefn
function Button_5_doIt(src, data, main)
close(main.figure);
end
## @deftypefn {} {} Frame_2_doIt (@var{src}, @var{data}, @var{main})
##
## Define a callback for default action of Frame_2 control.
##
## @end deftypefn
function Frame_2_doIt(src, data, main)
end
## @deftypefn {} {} cbox03_doIt (@var{src}, @var{data}, @var{main})
##
## Define a callback for default action of cbox03 control.
##
## @end deftypefn
function cbox03_doIt(src, data, main)
refresh();
end
## @deftypefn {} {} botonAceptar01_doIt (@var{src}, @var{data}, @var{main})
##
## Define a callback for default action of botonAceptar01 control.
##
## @end deftypefn
function botonAceptar01_doIt(src, data, main)
opcion = get(main.cbox03, 'value');
switch(opcion)
case 1
fprintf('Select option');
case 2
grap_sine();
refresh();
case 3
grap_cosine();
refresh();
endswitch
%refresh();
end
## @deftypefn {} {@var{ret} = } show_main()
##
## Create windows controls over a figure, link controls with callbacks and return
## a window struct representation.
##
## @end deftypefn
function ret = show_main()
_scrSize = get(0, "screensize");
_xPos = (_scrSize(3) - 564)/2;
_yPos = (_scrSize(4) - 246)/2;
main = figure ( ...
'Color', [0.941 0.941 0.941], ...
'Position', [_xPos _yPos 564 246], ...
'resize', 'on', ...
'windowstyle', 'modal', ...
'MenuBar', 'none');
set(main, 'visible', 'off');
Label_4 = uicontrol( ...
'parent',main, ...
'Style','text', ...
'Units', 'pixels', ...
'BackgroundColor', [0.941 0.941 0.941], ...
'FontAngle', 'normal', ...
'FontName', 'Arial', ...
'FontSize', 15, 'FontUnits', 'points', ...
'FontWeight', 'bold', ...
'ForegroundColor', [0.000 0.000 0.498], ...
'HorizontalAlignment', 'left', ...
'Position', [115 187 334 34], ...
'String', 'GUI', ...
'TooltipString', '');
Button_5 = uicontrol( ...
'parent',main, ...
'Style','pushbutton', ...
'Units', 'pixels', ...
'BackgroundColor', [0.941 0.941 0.941], ...
'FontAngle', 'normal', ...
'FontName', 'Arial', ...
'FontSize', 10, 'FontUnits', 'points', ...
'FontWeight', 'normal', ...
'ForegroundColor', [0.000 0.000 0.000], ...
'Position', [300 15 146 46], ...
'String', 'Close', ...
'TooltipString', '');
Frame_2 = uicontrol( ...
'parent',main, ...
'Style','frame', ...
'Units', 'pixels', ...
'BackgroundColor', [0.941 0.941 0.941], ...
'FontName', 'Arial', ...
'FontSize', 10, 'FontUnits', 'points', ...
'Position', [117 94 322 62], ...
'TooltipString', '');
cbox03 = uicontrol( ...
'parent',main, ...
'Style','popupmenu', ...
'Units', 'pixels', ...
'BackgroundColor', [0.941 0.941 0.941], ...
'FontAngle', 'normal', ...
'FontName', 'Arial', ...
'FontSize', 10, 'FontUnits', 'points', ...
'FontWeight', 'normal', ...
'ForegroundColor', [0.000 0.000 0.000], ...
'Position', [130 102 302 44], ...
'String', ' - Select option -|Sine|Cosine', ...
'TooltipString', '');
botonAceptar01 = uicontrol( ...
'parent',main, ...
'Style','pushbutton', ...
'Units', 'pixels', ...
'BackgroundColor', [0.941 0.941 0.941], ...
'FontAngle', 'normal', ...
'FontName', 'Arial', ...
'FontSize', 10, 'FontUnits', 'points', ...
'FontWeight', 'normal', ...
'ForegroundColor', [0.000 0.000 0.000], ...
'Position', [117 15 146 46], ...
'String', 'Acept', ...
'TooltipString', '');
main = struct( ...
'figure', main, ...
'Label_4', Label_4, ...
'Button_5', Button_5, ...
'Frame_2', Frame_2, ...
'cbox03', cbox03, ...
'botonAceptar01', botonAceptar01);
set (Button_5, 'callback', {@Button_5_doIt, main});
set (Frame_2, 'callback', {@Frame_2_doIt, main});
set (cbox03, 'callback', {@cbox03_doIt, main});
set (botonAceptar01, 'callback', {@botonAceptar01_doIt, main});
dlg = struct(main);
%
set(main.figure, 'visible', 'on');
ret = main;
end
The other four files display another windows with the sine and cosine plots (/path-to-test-gui/wnd/
grap_sine.m, grap_sine_def.m, grap_cosine.m and
grap_cosine_def.m).
Then, I do not know if the line octave::graphics_toolkit graphics_toolkit ("qt");
in file
test1.cc is right (because without this line the error is the same), or I need add some option in
mkoctfile command, that is:
mkoctfile --link-stand-alone test1.cc -L/usr/lib/x86_64-linux-gnu/octave/6.4.0/ "-Wl,-rpath,/usr/lib/x86_64-linux-gnu/octave/6.4.0/" -I/usr/include/octave-6.4.0/octave/ -I/path-to-test-gui/ -loctave -loctinterp -o test1
Or do I need something else? Sorry for the long post. Thanks.