QtCreator and ncurses - c++

I have a little program with C++ and ncurses in QtCreator:
#include <ncurses.h>
int main()
{
initscr();// inicializa pantalla
printw("Hello world!");
refresh();
getch();
endwin();
}
but when is opened xterm, it says:
Error opening terminal:unknown
It occured in Eclipse...
I've installed ncurses library correctly.
I run my code from console right.

On the Projects tab, Targets, Desktop, Run, Run Environment. Look for the TERM variable. If no found, add it and on the value of it, write xterm

Related

Why does nCurses (C++) block System() function?

I don't know if it is a thing just for me but I need to open a file with notepad on windows in a C++ program. I use at the same time ncurses for the pseudo-GUI but I noticed that all the "system()" calls don't work at all
void test() {
cout<<"\n\nTEST FUNCTION\n";
system("file.xml");
}
does open the file but if I use
void test() {
cout<<"\n\nTEST FUNCTION\n";
initscr();
system("file.xml");
endwin();
}
It doesn't work. With Windows' GetLastError() it gives me error 87 (invalid parameter) but for opening a file the command used is just the file name itself
Can someone please help me?
ncurses on Windows could refer to different environments:
Cygwin (where opening an xml file probably does not work, since system uses sh rather than cmd)
MinGW (which would use cmd)
WSL (undocumented like most of WSL, but probably like Cygwin)
With MinGW, ncurses switches the console mode by creating a screen buffer (analogous to xterm's alternate screen), which allows it to address cells on the visible screen. Doing that entails changing the inputs for that window. cmd would in that case change its behavior regarding file associations.

How to build an Xcode c++ program on terminal

I am using Xcode to program c++ projects. I am using ncurses library.
I am create a simple example, which works fine on terminal, but it does not work using xcode.
#include<ncurses.h>
#include<iostream>
int main()
{
char c;
initscr();
printw("Hello world!");
refresh();
c=getch();
endwin();
return 0;
}
On Xcode I get this error
Error opening terminal: unknown.
I am wondering that Xcode is not able to emulate an terminal. So, I try to change the "build phase" in xcode in order to build my project on terminal. I have used the proposed solution Automatically open terminal when debugging in Xcode?
But my project continue to run on xcode. What is the problem?

C++ console ncurses project - QtCreator doesn't show any output in xterm neither in console

#include <ncurses.h>
int main()
{
initscr();
addstr("Hello world");
refresh();
getch();
endwin();
return 0;
}
This basic application doesn't show any output when building and running in QtCreator 2.8.0.
When i run previously compiled in QtCreator program in separate terminal window, then it works fine. But when i run it under QtCreator (Ctrl-R or press "Run" button), then i see empty xterm window and no output. I guess this is somehow related with qtcreator_process_stub, which entitles that empty xterm window.
Try replacing
addstr("Hello world");
with
printw("Hello World !!!");
see
Found a solution.
In Project settings -> Environment -> TERM variable should be set to sane value like xterm
By default it was set to dumb

Windows Closes my SFML project after running

Everything is added correctly and I don't get any errors in the debug window. However when I go to RUN the application windows gives me the normal "SFMLProject.exe Not Responding" and then closes my application. I run a Tight computer and there is no virus protector doing anything to my application. I'm not sure what is wrong.
Here is the code I have but I don't think it will help. Just a simple "Music Stream"
#include <SFML/Audio.hpp>
int main()
{
sf::Music music;
if ( !music.openFromFile("music.ogg") )
return -1; // error
music.play();
return 0;
}
Your program shows Not responding because it returned a non-zero value. Somehow, SFML is not able to play the file. Check what the exact error is by reading the SFML documentation.
Where is your OGG file located? Is it in the Debug builds folder, or in the Release builds folder? Try providing the absolute path like C:/Path/To/Your/File/music.ogg

C++ on windows closes a program immediately after launching

I installed minGW and the eclipse CDT, and the console keeps doing something weird. The code of the program is
using namespace std;
#include <iostream>
int main() {
cout << "Hello, windows (8, c++)" << endl;
//system("PAUSE");
return 0;
}
You all know it, its the Hello World program. Now when I run this the Eclipse console displays some stuff about building, and then goes blank. And when I navigate to the HelloWorldProgram.exe in the explorer and run it, a windows flashes up and displays "hello world", but then immediately closes. When I do this on Mac OSX there's no problem, and the windows stays up until I decide to close it. Now I know there's a command
system("PAUSE") //I dont know what I need to import to use this. Could you tell me that too?
Which will give me more or less the same effect, but I'd like to know why Windows does it differently from OSX, and what I can do to fix it (bc this annoys the crap out of me).
Looking forward to your replies!
This happens on Windows because this is just the behavior of the Windows console. You'll have to open up the console manually and then running your program through the console you've opened if you don't want the window to close automatically once the program has executed.
You may want to take a look at these:
What is the Best Practice for Combating the Console Closing Issue?
https://superuser.com/questions/186562/how-can-i-keep-the-terminal-open
Don't use system("pause"), it's wrong for a multitude of reasons (read more about it here).
Put cin.get() before return and the window will stay open until you press enter.
If you want to just run your console program, you should open a console, and run it.
Apparently, the OSX version of Eclipse is configured to open a console, and run the program, and not close it. Maybe you can configure the Win version so, too.
You shouldn't meddle with your program to behave differently on another platform, instead wrap it into something that 'adapts' the behaviour.
Probably, you can tell eclipse to use "cmd /c 'yourprogram.exe && pause'", to open a command window and have it execute your program and then pause.
Just add getch(); before return, and add #include <conio.h>.