Fix error: Gtk-WARNING **: cannot open display:
Original Reporter info from Mantis: XakeR
-
Reporter name: Dmitry
Original Reporter info from Mantis: XakeR
- Reporter name: Dmitry
Description:
Description of the problem and fix it here:
https://forum.lazarus.freepascal.org/index.php/topic,47155.0.html
Steps to reproduce:
Under linux:
1. Make a GUI application project with source code:
program project1;
{$mode objfpc}{$H+}
uses {$IFDEF UNIX} {$IFDEF UseCThreads}
cthreads, {$ENDIF} {$ENDIF}
Unit1,
Interfaces,
Forms;
{$R *.res}
begin
if ParamCount > 0 then
begin
RequireDerivedFormResource := True;
Application.Scaled := True;
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end
else
begin
WriteLn('Hi, it''s a console app!');
end;
end.
- Compile and run when your X (Xorg) is down, you will get an error: Gtk-WARNING **: time: cannot open display.
Additional information:
For fixed it, i think need add in section "initialization" unit "Interfaces" next source code:
{$IFDEF UNIX}
function getenv(Name: PChar): PChar; cdecl; external 'c';
var
VENV_DISPLAY_IS_SET: boolean;
{$ENDIF}
initialization
{$IFDEF UNIX}
VENV_DISPLAY_IS_SET := getenv('DISPLAY') <> '';
if VENV_DISPLAY_IS_SET then
{$ENDIF}
CreateWidgetset(TGtk2WidgetSet);
finalization
{$IFDEF UNIX}
if VENV_DISPLAY_IS_SET then
{$ENDIF}
FreeWidgetSet;
Mantis conversion info:
- Mantis ID: 36206
- OS: Debian
- OS Build: 10
- Build: SVN revision 62111
- Platform: x86_64
- Version: 2.0.4