Re: Octave standalone programs that build a GUI display the error: graphics_toolkit: qt toolkit is not available

"Dmitri A. Sergatskov" <[email protected]> Mon, 17 Oct 2022 12:41:37 -0400
Newsgroups gmane.comp.gnu.octave.general
Message-ID <CAO+XyQLQWN-8fgdLKGdQnjt+uAHNb0=S_0WHggkTkiPvPX4uDw@mail.gmail.com>
What happens if you run "octave runApp.m"?

Dmitri.
-- 


On Mon, Oct 17, 2022 at 12:26 PM Michael Spilsbury <[email protected]>
wrote:

> Hello Dmitri,
>
> Only one things, when I call octave fron Linux shell, the call that you
> remark is "octave --gui runApp.m" and the m-file run without problems. But,
> how do I this call inside C++ script?
>
> I tryed with octave::cmdline_options cmdline_option; in test1.cc, and
> also adding before octave::source_file ("runApp.m"); the lines
> cmdline_option.gui (true); and cmdline_option.forced_interactive (true);
> but the same error was getting.
>
> Thanks.
>
>
>
> ______________________________
> Atentamente,
> Michael Spilsbury
>
> ------------------------------
> *De:* Dmitri A. Sergatskov <[email protected]>
> *Enviado:* lunes 17 de octubre de 2022 08:13
> *Para:* Michael Spilsbury <[email protected]>
> *Cc:* [email protected] <[email protected]>
> *Asunto:* Re: Octave standalone programs that build a GUI display the
> error: graphics_toolkit: qt toolkit is not available
>
> You should not be calling "octave-cli" directly. This is a binary
> linked w/o qt libraries. "octave" will start cli version,
> "octave --gui" will start octave gui.
>
> Dmitri.
> p.s. this mailing list is all but abandoned. Post on discourse
>  https://octave.discourse.group/c/help to get more attention.
>
>
> On Mon, Oct 17, 2022 at 10:01 AM Michael Spilsbury <
> [email protected]> wrote:
>
> <https://stackoverflow.com/posts/74077443/timeline>
>
> 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 availableAborted (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>
> intmain (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.
>
>
>
>
> ______________________________
> Atentamente,
> Michael Spilsbury
>
>
> ----------
> We are transitioning to a web based forum
> for community help discussions at
> https://octave.discourse.group/c/help
>
>


----------
We are transitioning to a web based forum
for community help discussions at
https://octave.discourse.group/c/help