Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to use ncurses and Qt Creator
Forum Updated to NodeBB v4.3 + New Features

how to use ncurses and Qt Creator

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 924 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JohnLocke
    wrote on 13 Dec 2023, 13:32 last edited by
    #1

    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

    J C 3 Replies Last reply 13 Dec 2023, 14:48
    0
    • J JohnLocke
      13 Dec 2023, 13:32

      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

      J Offline
      J Offline
      JonB
      wrote on 13 Dec 2023, 14:48 last edited by
      #2

      @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 same xterm 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?

      1 Reply Last reply
      0
      • J JohnLocke
        13 Dec 2023, 13:32

        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

        C Offline
        C Offline
        ChrisW67
        wrote on 14 Dec 2023, 08:46 last edited by
        #3

        @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.

        1 Reply Last reply
        1
        • J JohnLocke
          13 Dec 2023, 13:32

          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

          J Offline
          J Offline
          JonB
          wrote on 14 Dec 2023, 09:21 last edited by
          #4

          @JohnLocke
          As @ChrisW67 says, if the terminal launched by Creator does not have a environment variable named TERM this could easily be the cause. A quick way to find out would be to have your main() do something like system("env") or system("printenv"). That should show all its inherited environment variables. Look for TERM 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?

          C 1 Reply Last reply 15 Dec 2023, 03:23
          0
          • J JonB
            14 Dec 2023, 09:21

            @JohnLocke
            As @ChrisW67 says, if the terminal launched by Creator does not have a environment variable named TERM this could easily be the cause. A quick way to find out would be to have your main() do something like system("env") or system("printenv"). That should show all its inherited environment variables. Look for TERM 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?

            C Offline
            C Offline
            ChrisW67
            wrote on 15 Dec 2023, 03:23 last edited by
            #5

            @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.

            J 1 Reply Last reply 15 Dec 2023, 08:02
            0
            • C ChrisW67
              15 Dec 2023, 03:23

              @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.

              J Offline
              J Offline
              JonB
              wrote on 15 Dec 2023, 08:02 last edited by
              #6

              @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.

              C 1 Reply Last reply 15 Dec 2023, 11:50
              0
              • J JonB
                15 Dec 2023, 08:02

                @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.

                C Offline
                C Offline
                ChrisW67
                wrote on 15 Dec 2023, 11:50 last edited by
                #7

                @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 Reply Last reply
                1

                1/7

                13 Dec 2023, 13:32

                • Login

                • Login or register to search.
                1 out of 7
                • First post
                  1/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved