Qt学习之路之菜单打开网页

点击菜单的选项后,可以打开本地浏览器打开一组特定的网页。不废话了,上代码。

在此,感谢博主:http://blog.sina.com.cn/liang19890820

      menu_widget.h 代码

#ifndef MENUWIDGET
#define MENUWIDGET
#include <QMenu>
#include <QTextCodec>
#include <QDesktopServices>
#include <QApplication>
#include <QUrl>

class MenuWidget : public QMenu
{
	Q_OBJECT
public:
	explicit MenuWidget(QWidget *parent = 0);

	public slots:
		void slotShowHomeWeb();				//主页
		void slotShowNewCharacterWeb();	//新特性
		void slotShowCheckUpdateWeb();	//更新
		void slotShowInterNaVerWeb();		//国际版
		void slotShowHelpOnlineWeb();		//在线求助
		void slotShowPlatformHelpWeb();	//论坛求助
		void slotShowAboutUsWeb();			//关于我们
		//void slotQuit();								//退出

private:
	QAction *AC_Home;					//主页
	QAction *AC_NewCharacter;		//新特性
	QAction *AC_CheckUpdate;			//更新
	QAction *AC_InterNaVer;				//国际版
	QAction *AC_HelpOnline;				//在线帮助
	QAction *AC_PlatformHelp;			//平台/论坛求助	
	QAction *AC_AboutUs;				//关于
	QAction *AC_Quit;						//退出
};
#endif		//MENUWIDGET

menuwidget.cpp代码如下

#include "menu_widget.h"

MenuWidget::MenuWidget(QWidget *widget) : QMenu(widget)
{
	//---解决QT5下中文乱码
	QTextCodec *codec = QTextCodec::codecForName("GB18030");

	//----创建菜单项
	AC_Home = new QAction(codec->toUnicode("主页"), this);
	AC_InterNaVer = new QAction(codec->toUnicode("国际版"), this);
	AC_NewCharacter = new QAction(codec->toUnicode("新版本特性"), this);
	AC_CheckUpdate = new QAction(codec->toUnicode("检查更新"), this);
	AC_HelpOnline = new QAction(codec->toUnicode("在线求助"), this);
	AC_PlatformHelp = new QAction(codec->toUnicode("论坛求助"), this);
	AC_AboutUs = new QAction(codec->toUnicode("关于易莲"), this);
	AC_Quit = new QAction(codec->toUnicode("退出"), this);

	//----添加菜单项
	addAction(AC_Home);
	addAction(AC_NewCharacter);
	addAction(AC_CheckUpdate);
	addAction(AC_InterNaVer);
	addAction(AC_HelpOnline);
	addAction(AC_PlatformHelp);
	addAction(AC_AboutUs);
	addAction(AC_Quit);

	//----设置信号与槽
	connect(AC_Home, SIGNAL(triggered()), this, SLOT(slotShowHomeWeb()));
	connect(AC_NewCharacter, SIGNAL(triggered()), this, SLOT(slotShowNewCharacterWeb()));
	connect(AC_CheckUpdate, SIGNAL(triggered()), this, SLOT(slotShowCheckUpdateWeb()));
	connect(AC_InterNaVer, SIGNAL(triggered()), this, SLOT(slotShowInterNaVerWeb()));
	connect(AC_HelpOnline, SIGNAL(triggered()), this, SLOT(slotShowHelpOnlineWeb()));
	connect(AC_PlatformHelp, SIGNAL(triggered()), this, SLOT(slotShowPlatformHelpWeb()));
	connect(AC_AboutUs, SIGNAL(triggered()), this, SLOT(slotShowAboutUsWeb()));
	connect(AC_Quit, SIGNAL(triggered()), qApp, SLOT(quit()));
}

//---显示主页
void MenuWidget::slotShowHomeWeb()
{
	QUrl Url("http://im.qq.com/");
	QDesktopServices::openUrl(Url);
}

//---x新特性
void MenuWidget::slotShowNewCharacterWeb()
{
	QUrl Url("http://im.qq.com/pcqq/");
	QDesktopServices::openUrl(Url);
}

//--版本更新
void MenuWidget::slotShowCheckUpdateWeb()
{
	QUrl Url("http://im.qq.com/download/pc.shtml");
	QDesktopServices::openUrl(Url);
}

//---国际版
void MenuWidget::slotShowInterNaVerWeb()
{
	QUrl Url("http://www.imqq.com/");
	QDesktopServices::openUrl(Url);
}

//---在线求助
void MenuWidget::slotShowHelpOnlineWeb()
{
	QUrl Url("http://kf.qq.com/product/QQ.html");
	QDesktopServices::openUrl(Url);
}

//---论坛求助
void MenuWidget::slotShowPlatformHelpWeb()
{
	QUrl Url("http://blog.imqq.com/");
	QDesktopServices::openUrl(Url);
}

//---关于我们
void MenuWidget::slotShowAboutUsWeb()
{

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值