[solved] Problem with console



  • Hi i have a problem with my console
    I cannot display it, i had only the first message "please choose an xml....." in the application output.
    This is my code, And in my project.pro i had of course add QT += gui
    @
    #include<QApplication>
    ....
    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);

    MIRSpecLoad load;
    MIRSystem system;
    
    string fn;
    QString sfn;
    QFile f;
    
    do
    {
    std::cout<<"please choose an xml file name"<<std::endl;
    cin>>fn;
    sfn=sfn.fromUtf8(fn.c_str(),-1);
    QFile f(sfn);
    if (!(f.exists())) {cout<<"The file does not exist"<<endl; }
    }while (!(f.exists()));
    
    
      if (!load.openFile&#40;sfn&#41;)
      {
          std::cerr << "Failed to open the given file." << std::endl;
          return 0;
      }
      if(!load.parseSystem&#40;&system&#41;&#41;
      {
          std::cerr << "Unable to parse system." << std::endl;
          return 0;
      }
    

    return a.exec();

    }@

    Please can any one help me??



  • Hi, I don't think you can use std::cout or any other std console output in combination with the QApplication. As far as I know it will block the output until you exit the application and only after that you'll see the output from std::cout.

    I looked at some Qt example apps and I think they are using this to print to the console:
    @
    std::fputs("test", stdout);
    std::printf("test %d", 123);
    @
    i don't know if that makes any difference, but you could still use QDebug to print to the console, but that is only supposed for debug out usually :D


Log in to reply
 

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