Recent

Author Topic: Gtk-WARNING **: cannot open display:  (Read 551 times)

XakeR

  • New Member
  • *
  • Posts: 10
Gtk-WARNING **: cannot open display:
« on: October 22, 2019, 10:57:48 pm »
The task is:
It is necessary that according to the flag passed to the application, for example:
"app.exe -t gui" or " app.exe -t console"
the application ran in either GUI or console mode, depending on the flag.
And here is code written all works under Windows, but not under Linux!
When I run my app under Windows, like this:
"app.exe -t gui" - I see forms and accordingly my GUI.
When I'm running my app under Windows like this:
"app.exe -t console " it works as a console and everything is fine
BUT when I run my application under Linux, like this:
"app -t gui "of course if X is started then everything is fine, otherwise I see an error: "Gtk-WARNING **: time: cannot open display" and it is clear.
BUT when I run my application under Linux, like this:
"app -t console "that if X is started all is good BUT if is not present, I see an error:" Gtk-WARNING **: time: cannot open display " though I do not use at runtime on ANY GUI elements.
Attention my questions:
1. How can I not initialize GTK from my application code at runtime ?
2. Where do I get the message "Gtk-WARNING **:..."?

XakeR

  • New Member
  • *
  • Posts: 10
Re: Gtk-WARNING **: cannot open display:
« Reply #1 on: October 23, 2019, 02:59:42 am »
I found a solution, it's all in the module initialization block Intrfaces in section "initialization":
CreateWidgetSet(TGtk2WidgetSet);

May be need replace:
Code: Pascal  [Select]
  1. initialization
  2.   CreateWidgetset(TGtk2WidgetSet);
  3. finalization
  4.   FreeWidgetSet;
On:
Code: Pascal  [Select]
  1. {$IFDEF UNIX}
  2. function getenv(Name: PChar): PChar; cdecl; external 'c';
  3. var
  4.   VENV_DISPLAY_IS_SET: boolean;
  5. {$ENDIF}
  6. initialization
  7.   {$IFDEF UNIX}
  8.   VENV_DISPLAY_IS_SET := getenv('DISPLAY') <> '';
  9.   if VENV_DISPLAY_IS_SET then
  10.   {$ENDIF}
  11.     CreateWidgetset(TGtk2WidgetSet);  
  12. finalization
  13.   {$IFDEF UNIX}
  14.   if VENV_DISPLAY_IS_SET then
  15.   {$ENDIF}
  16.     FreeWidgetSet;
« Last Edit: October 23, 2019, 12:06:25 pm by XakeR »

XakeR

  • New Member
  • *
  • Posts: 10

zeljko

  • Hero Member
  • *****
  • Posts: 1080
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Gtk-WARNING **: cannot open display:
« Reply #3 on: October 23, 2019, 02:40:30 pm »
I'm not sure that {$IFDEF UNIX} and checking $DISPLAY should work on Macs (maybe someone still uses gtk on mac).

XakeR

  • New Member
  • *
  • Posts: 10
Re: Gtk-WARNING **: cannot open display:
« Reply #4 on: October 28, 2019, 08:37:27 am »

zeljko

  • Hero Member
  • *****
  • Posts: 1080
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Gtk-WARNING **: cannot open display:
« Reply #5 on: October 28, 2019, 06:02:43 pm »
That's nice article about prealpha status (features) of wayland. This is about
Lcl widgetset non creation when we are on headless server, and it can flood our bygtracker about crashes when application starts.
Note that qt5 widgetset already have solution for headless:
Yourprogram -platform minimal  will start your lclqt5 application on headless server