LINUX用QT进行图像显示

由于项目需要, 需要在LINUX上将两个摄像头的数据同时显示在一个最大化窗体上,实现监控。  以前都比较习惯在WINDOWS平台上用MFC或JAVA写界面, 转到LINUX上,只好求取于QT大神了。 


下面是主函数源文件

#include <QApplication>
#include "window.h"

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    Window window;
    window.show();
    return app.exec();
}

窗体源文件

/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
**   * Redistributions of source code must retain the above copyright
**     notice, this list of conditions and the following disclaimer.
**   * Redistributions in binary form must reproduce the above copyright
**     notice, this list of conditions and the following disclaimer in
**     the documentation and/or other materials provided with the
**     distribution.
**   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
**     the names of its contributors may be used to endorse or promote
**     products derived from this software without specific prior written
**     permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
** $QT_END_LICENSE$
**
****************************************************************************/

#include <QtGui>
#include "glwidget.h"
#include "widget.h"
#include "window.h"

//! [0]
Window::Window()
    : QWidget()
{
    Widget *native = new Widget(&helper1, this);
    //Widget *cam2   = new Widget(&helper, this);

    GLWidget *openGL = new GLWidget(&helper2, this);

    QLabel *nativeLabel = new QLabel(tr("IPCAM-1"));
    nativeLabel->setAlignment(Qt::AlignHCenter);
    QLabel *openGLLabel = new QLabel(tr("IPCAM-2"));
    openGLLabel->setAlignment(Qt::AlignHCenter);

    QGridLayout *layout = new QGridLayout;
    layout->addWidget(native, 1, 0);
    layout->addWidget(openGL,   1, 1);
    layout->addWidget(nativeLabel, 0, 0);
    layout->addWidget(openGLLabel, 0, 1);
    setLayout(layout);

    QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), native, SLOT(animate()));
    connect(timer, SIGNAL(timeout()), openGL, SLOT(animate()));
    timer->start(50);

    setWindowTitle(tr("2D Painting on IPCAM-1 and IPCAM-2 Widgets"));
}
//! [0]
以上代码也挺容易看懂的,跟JAVA的窗体有点相像个人觉得, 声明了两个Widget类, 对两个显示部分独立显示, 后面用一个框架管理容器将它们包含进去, 后面加入一个定时器,50ms去刷新一张图片, 这里有用到QT的信号与槽, 这里是跟MFC有些不一样的地方, MFC用的是消息映射机制, 微软弄的一套机制, 而JAVA用的是事件响应,其实都是大同小异的, 懂其中一个,另外的都是可以融会贯通的。 

后面就不一一贴出来了,大体思路就是定时去刷新图片区,我用的是QPainter的drawImage方法来进行绘图。 有需要可以下我的工程来进行修改, 当时也只是一个DEMO例子而已。 工程链接: 点击打开链接

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值