• 21290阅读
  • 11回复

【提问】QT里怎样能够有终端输出啊? [复制链接]

上一主题 下一主题
离线m31
 
只看楼主 倒序阅读 楼主  发表于: 2005-08-21
我发现Qt里执行
cout<<"output a string";
cin>>in;
等语句没有反应。( 终端没有输出和输入提示。即使在终端运行都是这样)


我试了
#include <QTextStream>
int main(int argc, char *argv[])
{
QTextStream qout(stdout);
qout<<"string\n";

return 0;
}

还是没有输出啊。是不是要加点什么啊?
谢谢!!
[ 此贴被XChinux在2005-08-21 22:50重新编辑 ]
离线XChinux

只看该作者 1楼 发表于: 2005-08-21
可能是标准输入和输出被重新设置了吧,我找找有感于原因
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线acefunware

只看该作者 2楼 发表于: 2005-08-21
QString与printf的%s

qt 4里
QString str("hello");
printf("%s\n", str.data()); //只打印出h
//这是由于在qt4里每个char存留unicode,第二字节为零
解决方法
1. printf("%s\n", qPrintable(str));
//qPrintable在qt文档里没有出现,但可在其源码里发现
2. printf("%s\n", str.toLatin1());
//toLatin1,toUtf8,toLocal8bit返回QByteArray,可以自动转成 char*


希望对你有用
来自:
http://spaces.msn.com/members/nzt/?partqs=cat%3DQt&_c11_blogpart_blogpart=blogview&_c=blogpart
email:acefunware@yahoo.com.cn
blog:http://acefunware.shineblog.com
离线XChinux

只看该作者 3楼 发表于: 2005-08-21
确实是有输出的,你可以用
qtapp > out.txt
看看out.txt里的东西是什么,就知道已经输出了。
可能换一个支持Unicode字符的终端,就能在终端看到输出的字符了。
平常用的终端都不是Unicode的
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线m31
只看该作者 4楼 发表于: 2005-08-22
thank you!
but the methods mentioned above don't work.

i used google to search the answer:
http://www.qtforum.org/thread.php?threadid=3466&sid=7bdc70de5013490f6813ba10a889e924

{
12.10.2004 21:34 Forum: Qt Programming
Hi,
try to use qmake and input the following line

win32:CONFIG += console in the *.pro file.

to tell windows that you have a console app.

Christian
}

i tried and it did work!
离线XChinux

只看该作者 5楼 发表于: 2005-08-22
好方法,加精华
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线acefunware

只看该作者 6楼 发表于: 2005-08-27
好办法
email:acefunware@yahoo.com.cn
blog:http://acefunware.shineblog.com
离线eryue
只看该作者 7楼 发表于: 2005-08-29
我在qt3.3.3里:
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>

1     cout<<"Hello, let's plot !"<<endl;

2   QString   strOpenFile;
    QFile file(strOpenFile);
    cout<<strOpenFile<<endl;
    temp = file.size();
    cout<<temp<<endl;

都有结果:
1 Hello, let's plot !
2 /data3/chenxh/haozj/Qt/plot/drawline/accum.txt
10750
离线wxr159835
只看该作者 8楼 发表于: 2011-01-10
把  win32:CONFIG += console  加到.pro里面
离线梅克斯
只看该作者 9楼 发表于: 2011-01-11
qDebug
可以输出
离线guang0908090
只看该作者 10楼 发表于: 2011-07-27
快乐每一天
离线wenxuan
只看该作者 11楼 发表于: 2011-07-29
qDebug qWarning
快速回复
限100 字节
 
上一个 下一个