how to use ncurses and Qt Creator
-
wrote on 13 Dec 2023, 13:32 last edited by
I usually call my app from Qt Creator using run command (green arrow), set to open in external terminal, so it opens in xterm (ubuntu).
Code below is to set terminal to ncurses, need for educational purposes
If I use standard method to run app from Qt Creator it throws:
Error opening terminal: unknown.if I open it with terminal using ./AppName it works
Process exited with code: 1
qmake:
# MyNcursesApp.pro QT -= gui CONFIG += console c++11 CONFIG -= app_bundle # Add the following line to ensure proper terminal handling CONFIG += link_pkgconfig PKGCONFIG += ncurses SOURCES += main.cpp
welcome code:
#include <ncurses.h> int main() { initscr(); // Initialize the ncurses library printw("Hello, ncurses!"); refresh(); // Refresh the screen getch(); // Wait for a key press endwin(); // End the ncurses library return 0; }
kindly advise
-
I usually call my app from Qt Creator using run command (green arrow), set to open in external terminal, so it opens in xterm (ubuntu).
Code below is to set terminal to ncurses, need for educational purposes
If I use standard method to run app from Qt Creator it throws:
Error opening terminal: unknown.if I open it with terminal using ./AppName it works
Process exited with code: 1
qmake:
# MyNcursesApp.pro QT -= gui CONFIG += console c++11 CONFIG -= app_bundle # Add the following line to ensure proper terminal handling CONFIG += link_pkgconfig PKGCONFIG += ncurses SOURCES += main.cpp
welcome code:
#include <ncurses.h> int main() { initscr(); // Initialize the ncurses library printw("Hello, ncurses!"); refresh(); // Refresh the screen getch(); // Wait for a key press endwin(); // End the ncurses library return 0; }
kindly advise
wrote on 13 Dec 2023, 14:48 last edited by@JohnLocke said in how to use ncurses and Qt Creator:
if I open it with terminal using ./AppName it works
That "terminal" may not necessarily be
xterm
. Have you tried your app in just the samexterm
as you are having Creator open for you?If I use standard method to run app from Qt Creator it throws:
Error opening terminal: unknown
It is not clear whether you mean you get this error when Creator opens terminal for you or a message output by your application/curses library?
-
I usually call my app from Qt Creator using run command (green arrow), set to open in external terminal, so it opens in xterm (ubuntu).
Code below is to set terminal to ncurses, need for educational purposes
If I use standard method to run app from Qt Creator it throws:
Error opening terminal: unknown.if I open it with terminal using ./AppName it works
Process exited with code: 1
qmake:
# MyNcursesApp.pro QT -= gui CONFIG += console c++11 CONFIG -= app_bundle # Add the following line to ensure proper terminal handling CONFIG += link_pkgconfig PKGCONFIG += ncurses SOURCES += main.cpp
welcome code:
#include <ncurses.h> int main() { initscr(); // Initialize the ncurses library printw("Hello, ncurses!"); refresh(); // Refresh the screen getch(); // Wait for a key press endwin(); // End the ncurses library return 0; }
kindly advise
wrote on 14 Dec 2023, 08:46 last edited by@JohnLocke said in how to use ncurses and Qt Creator:
If I use standard method to run app from Qt Creator it throws:
Error opening terminal: unknown.The default (I assume that's what you mean by "standard") method used by Creator when running applications does not provide a fully fledged terminal to the application.
Ncurses initscr() is documented thus:
The initscr() function determines the terminal type and initialises all implementation data structures. The environment variable specifies the terminal type.
The environment variable is TERM and, since there is not a full terminal emulation, it is likely unset. When you launch your application from Creator in a separate terminal emulator (xterm, konsole whatever) that variable is set.
-
I usually call my app from Qt Creator using run command (green arrow), set to open in external terminal, so it opens in xterm (ubuntu).
Code below is to set terminal to ncurses, need for educational purposes
If I use standard method to run app from Qt Creator it throws:
Error opening terminal: unknown.if I open it with terminal using ./AppName it works
Process exited with code: 1
qmake:
# MyNcursesApp.pro QT -= gui CONFIG += console c++11 CONFIG -= app_bundle # Add the following line to ensure proper terminal handling CONFIG += link_pkgconfig PKGCONFIG += ncurses SOURCES += main.cpp
welcome code:
#include <ncurses.h> int main() { initscr(); // Initialize the ncurses library printw("Hello, ncurses!"); refresh(); // Refresh the screen getch(); // Wait for a key press endwin(); // End the ncurses library return 0; }
kindly advise
wrote on 14 Dec 2023, 09:21 last edited by@JohnLocke
As @ChrisW67 says, if the terminal launched by Creator does not have a environment variable namedTERM
this could easily be the cause. A quick way to find out would be to have yourmain()
do something likesystem("env")
orsystem("printenv")
. That should show all its inherited environment variables. Look forTERM
among them and/or compare against the output from this command running your application in a terminal window where it does work successfully.I am not quite sure what @ChrisW67 means by "does not provide a fully fledged terminal to the application" or "since there is not a full terminal emulation". So far as I recall Creator has a setting where you can see/change what the command is for the terminal you are launching, and I asked earlier whether that is indeed
xterm
? -
@JohnLocke
As @ChrisW67 says, if the terminal launched by Creator does not have a environment variable namedTERM
this could easily be the cause. A quick way to find out would be to have yourmain()
do something likesystem("env")
orsystem("printenv")
. That should show all its inherited environment variables. Look forTERM
among them and/or compare against the output from this command running your application in a terminal window where it does work successfully.I am not quite sure what @ChrisW67 means by "does not provide a fully fledged terminal to the application" or "since there is not a full terminal emulation". So far as I recall Creator has a setting where you can see/change what the command is for the terminal you are launching, and I asked earlier whether that is indeed
xterm
?wrote on 15 Dec 2023, 03:23 last edited by@JonB said in how to use ncurses and Qt Creator:
I am not quite sure what @ChrisW67 means by "does not provide a fully fledged terminal to the application" or "since there is not a full terminal emulation".
Just that, unless you use the Qt Creator "Run in terminal" option the application is run in a stub launcher that may not be a full terminal that NCurse can use. When "Run in terminal" is selected, and the "Use internal terminal" disabled, a separate xterm/konsole is launched to start the program.
I've just tried your printenv suggestion (with the NCurses Hello World above) and neither environment gives me TERM, and neither works. A manually launched konsole gives TERM "xterm-256color" and the test app does work. Go figure.
-
@JonB said in how to use ncurses and Qt Creator:
I am not quite sure what @ChrisW67 means by "does not provide a fully fledged terminal to the application" or "since there is not a full terminal emulation".
Just that, unless you use the Qt Creator "Run in terminal" option the application is run in a stub launcher that may not be a full terminal that NCurse can use. When "Run in terminal" is selected, and the "Use internal terminal" disabled, a separate xterm/konsole is launched to start the program.
I've just tried your printenv suggestion (with the NCurses Hello World above) and neither environment gives me TERM, and neither works. A manually launched konsole gives TERM "xterm-256color" and the test app does work. Go figure.
wrote on 15 Dec 2023, 08:02 last edited by@ChrisW67 said in how to use ncurses and Qt Creator:
"Use internal terminal"
I'm not sure I knew there was an "internal terminal", I only ever used "Run in terminal" where it runs xterm.
I think you are confirming it is the lack of a
TERM
variable which causes ncurses to barf. -
@ChrisW67 said in how to use ncurses and Qt Creator:
"Use internal terminal"
I'm not sure I knew there was an "internal terminal", I only ever used "Run in terminal" where it runs xterm.
I think you are confirming it is the lack of a
TERM
variable which causes ncurses to barf.wrote on 15 Dec 2023, 11:50 last edited by@JonB said in how to use ncurses and Qt Creator:
I'm not sure I knew there was an "internal terminal"
Nor did I until today.
1/7