I cant use console application



  • hi

    when i build a console program i cant see results in terminal page . just opened a empty terminal page and doesnt show anythings!

    i dont know why and i'll be happy if anyone helps me



  • Can you please post your written code to see, what's wrong?
    I am not sure, what you meen with "doesn't show anything". Which system are you using?



  • This is far too vague to say anything helpful.

    Please say at least which platform you are on and show a meaningful piece of your code.



  • thanks dears .

    i have not any code. just i tested it and didnt get any result .

    my simple code is :
    @
    #include <QCoreApplication>
    #include <iostream>

    using namespace std;

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);
    cout<<"aaaa";
    //printf("ssss");
    return a.exec();
    }
    @

    and i am in ubuntu 12.04 OS with qtcreator 2.5 and qt4.8.1 sdk.

    when i execute that code a empty terminal box opens and i can write into but it doesnt any work!





  • this code is in .pro-file too :

    @
    QT += core

    QT -= gui

    TARGET = test1
    CONFIG += console
    CONFIG -= app_bundle

    TEMPLATE = app

    SOURCES += main.cpp
    @



  • I'm not quite sure about how this is on Linux, but on the Windows platform applications can be compiled as "Windows" or as "Console" applications. That's a Linker option. If you compile as "Windows", which is the default for GUI apps, then the app doesn't have a console. And even if you run it from a console - or allocate a console at runtime via AllocConsole() function - output to the console via "stdout" or "cout" doesn't work. Bummer! That's because the C Runtime never binds the stdout/stderr or cout/cerr to the console - because it doesn't expect a console to be there. There are some workarounds for that. Maybe on Linux there is a similar issue. I'm not quite sure. Maybe somebody more familiar with Linux can give an answer about that...



  • @
    //This is working!!!, put endl for end cout

    #include <QCoreApplication>
    #include <iostream>
     
    using namespace std;
     
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
        cout<<"aaaa" << endl;
        //printf("ssss");
        return a.exec(&#41;;
    }
    

    @



  • [quote author="batista" date="1361676392"]@
    //This is working!!!, put endl for end cout

    #include <QCoreApplication>
    #include <iostream>
     
    using namespace std;
     
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
        cout<<"aaaa" << endl;
        //printf("ssss");
        return a.exec(&#41;;
    }
    

    @[/quote]

    i put it but didnt work !



  • @
    //My test in debian and ubuntu 12.10 work fine.

    batista@dellxps:~/NetBeansProjects/QtTes$ cat test.cpp
    #include <QCoreApplication>
    #include <iostream>

    using namespace std;
     
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
        cout<<"aaaa" << endl;
        //printf("ssss");
        return a.exec&#40;&#41;;
    }
    

    batista@dellxps:~/NetBeansProjects/QtTes$ ./QtTes
    aaaa

    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.