Important: Please read the Qt Code of Conduct -

[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 i had of course add QT += gui
    int main(int argc, char *argv[])
    QApplication a(argc, argv);

    MIRSpecLoad load;
    MIRSystem system;
    string fn;
    QString sfn;
    QFile f;
    std::cout<<"please choose an xml file name"<<std::endl;
    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;
          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