在Qt 4 Console Application工程中添加Widgets的错误处理

创建Qt 4 Console Application工程后,如果在工程中添加Widgets,则在编译运行时会出现一些错误,解决方法如下:

 

一、


编译时出现大量的“undefined reference to XX”,以及“collect2: ld returned 1 exit status”。


解决方法:


打开<project_name.pro>文件,删除如下几行:

 

QT       -= gui
CONFIG   += console
CONFIG   -= app_bundle

 

console:包含该配置,将为程序创建一个控制台;
app_bundle:编写MAC OS下GUI专用,具体参考

<http://www.cppblog.com/biao/archive/2009/04/30/81602.aspx>


On the Mac, a GUI application must be built and run from a bundle. A bundle is a directory structure that appears as a single entity when viewed in the Finder. A bundle for an application typcially contains the executable and all the resources it needs.


The bundle provides many advantages to the user. One primary advantage is that, since it is a single entity, it allows for drag-and-drop installation. As a programmer you can access bundle information in your own code. This is specific to Mac OS X and beyond the scope of this document. More information about bundles is available on Apple's Developer Website.


A Qt command line application on Mac OS X works similar to a command line application on Unix and Windows. You probably don't want to run it in a bundle: Add this to your application's .pro:
 CONFIG-=app_bundle

 

 

 

二、


运行时提示“QWidget: Cannot create a QWidget when no GUI is being used”,然后退出


解决方法:


将程序中的
#include <QtCore/QCoreApplication>
...
<QtCore/QCoreApplication>app(argc, argv);

替换为
#include <QtGui/QApplication>
...
QApplication  app(argc, argv);

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值