选择创建控制台生成以下代码
#include <QtCore/QCoreApplication>
int main(int argc, char *argv[])
{
QCoreApplicationa(argc, argv);
returna.exec();
}
.pro文件如下
#-------------------------------------------------
#
# Project created by QtCreator 2012-03-30T15:34:14
#
#-------------------------------------------------
QT += core
QT -= gui
TARGET = test1
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
如果要想变成带窗口的程序需要做如下改变
QCoreApplication a(argc, argv);
变成
QApplication a(argc, argv);
QCoreApplication
是控制台的Application
QApplication
是带窗口的Application
最后变化如下
#include <QtGui/QApplication>
#include <QtCore>
#include <QWebView>
#include <QWebFrame>
#include <QThread>
#include <QUrl>
int main(int argc, char *argv[])
{
QApplicationa(argc, argv);
QTextStreamout(stdout);
out<< "start";
QWebView* pWebView = new QWebView();
pWebView->load(QUrl("http://bj.58.com"));
pWebView->show();
out<<pWebView->page()->mainFrame()->toHtml();
//SleeperThread::sleep(-1);
printf("aaa");
returna.exec();
}
#-------------------------------------------------
#
# Project created by QtCreator 2012-03-30T14:58:34
#
#-------------------------------------------------
QT += core gui webkit network
#QT -= gui
TARGET = MyBlog
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
SOURCES += main.cpp