CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2010
    Posts
    907

    Cannot compile a QT project using mingw32

    Code:
     
    #ifndef Widget_H
    #define Widget_H
    
    #include <QtOgrePrereqs.h>
    
    // Boost + Qt5 workaround to avoid Macro argument mismatch error.
     
    #include <OgreCamera.h>
    #include <OgreEntity.h>
    #include <OgreLogManager.h>
    #include <OgreRoot.h>
    #include <OgreViewport.h>
    #include <OgreSceneManager.h>
    #include <OgreRenderWindow.h>
    #include <OgreConfigFile.h>
    
    #include <OISEvents.h>
    #include <OISInputManager.h>
    #include <OISKeyboard.h>
    #include <OISMouse.h>
    
    #include <ColouredRectangle.h>
    #include <CameraMan.h>
    #include <QWidget.h>
    #include "OverlayWidget.h"
     
    
    #define QTLIB	0
    #define OISLIB	1
    
    #define INPUTLIB QTLIB
    
    namespace QOgre
    {
         class Widget : public QWidget
        {
    
    	Q_OBJECT
    
        public:
                #ifdef QWIDGET_H
                            Widget( QWidget *parent = 0, Qt::WindowFlags flags = 0);
                #else
                            Widget();
                #endif
    	virtual ~Widget(void);
    	virtual void	go(Ogre::Root* root, Ogre::SceneManager* mgr = NULL);
    	QPaintEngine*	paintEngine() const; // Turn off QTs paint engine for the Ogre widget.
    	Ogre::SceneManager* getSceneManager() {return mSceneMgr;}
    	Ogre::String	mFPS;
    	bool		mSystemInitialized;
    	virtual void	updateOgre(float timeSinceLastFrame);
    	virtual void	setViewportBackground(Ogre::ColourValue top, Ogre::ColourValue bottom);
        protected:
    	bool setup();
    	bool configure(void);
    	void chooseSceneManager(void);
    	void createCamera(void);
    	void createScene(void);
    	void destroyScene(void);
    	void createViewports(void);
    	void setupResources(void);
    	void createResourceListener(void);
    	void loadResources(void);
    
    	Ogre::Root*	    mRoot;
    	Ogre::Camera*	    mCamera;
    	Ogre::SceneManager* mSceneMgr;
    	Ogre::RenderWindow* mWindow;
    	Ogre::String	    mResourcesCfg;
    	Ogre::String	    mPluginsCfg;
    	Ogre::Real	    mTimeSinceLastFrame;
    	QOgre::CameraMan*   mCameraMan;
    	bool mShutDown;
    	bool mPassedSM;
    
        private:
    	void paintEvent(QPaintEvent *e);
    	void resizeEvent(QResizeEvent *e);
    	void mouseMoveEvent(QMouseEvent *e);
    	void mousePressEvent(QMouseEvent *e);
    	void mouseReleaseEvent(QMouseEvent *e);
    	void wheelEvent(QWheelEvent *e);
    	void keyPressEvent(QKeyEvent *e);
    	void keyReleaseEvent(QKeyEvent *e);
    	bool updateExternalSystems();
    	Ogre::Vector2		    mAbsolute;
    	Ogre::Vector2		    mRelative;
    	QOgre::OverlayWidget*	    mOverlayWidget;
        };
    }
    #endif // Widget_H
    Code:
    /*
     * ----------------------------------------------------------------------------
     * "THE BEER-WARE LICENSE" (Revision 42):
     * Ilija Boshkov <Mind Calamity> wrote this file. As long as you retain this notice you
     * can do whatever you want with this stuff. If we meet some day, and you think
     * this stuff is worth it, you can buy me a beer in return Poul-Henning Kamp
     * ----------------------------------------------------------------------------
     */
    
    /*/////////////////////////////////////////////////////////////////////////////////
    /// Copyright (c) 2012 Ilija Boshkov
    //
    /// The MIT License
    ///
    /// Permission is hereby granted, free of charge, to any person obtaining a copy
    /// of this software and associated documentation files (the "Software"), to deal
    /// in the Software without restriction, including without limitation the rights
    /// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    /// copies of the Software, and to permit persons to whom the Software is
    /// furnished to do so, subject to the following conditions:
    ///
    /// The above copyright notice and this permission notice shall be included in
    /// all copies or substantial portions of the Software.
    ///
    /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    /// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    /// THE SOFTWARE.
    ////////////////////////////////////////////////////////////////////////////////*/
    
    #include "Widget.h"
    using namespace QOgre;
    
    //----------------------------------------------------------------------------------------
    void OverlayWidget::paintEvent(QPaintEvent* evt)
    {
        QPainter painter(this);
        painter.setClipRect(0,0,width(),height());
        painter.setBrush(QBrush(QColor(0,0,0)));
        painter.fillRect(QRectF(0,0,width(),height()), QColor(0,0,0));
        painter.setPen(QColor(210,210,210));
        painter.drawText(QRectF(0,0,width(),height()),msgstr,QTextOption(Qt::AlignVCenter | Qt::AlignHCenter));
    }
    //----------------------------------------------------------------------------------------
    
    //-------------------------------------------------------------------------------------
    
    #ifdef QWIDGET_H
        Widget::Widget( QWidget* parent, Qt::WindowFlags flags)
            :  QWidget(parent, flags),
            mRoot(0),
            mCamera(0),
            mSceneMgr(0),
            mWindow(0),
            mShutDown(false),
            mPassedSM(false),
            mSystemInitialized(false),
            mResourcesCfg(""),
            mPluginsCfg("")
        {  
            setAttribute(Qt::WA_OpaquePaintEvent);
            setAttribute(Qt::WA_PaintOnScreen);
            setMinimumSize(240,240);
            resize(800,600);
            setFocusPolicy(Qt::StrongFocus);
            setMouseTracking(true);
            mOverlayWidget = new OverlayWidget(this);
            QVBoxLayout *layout = new QVBoxLayout();
            layout->setMargin(0);
            layout->addWidget(mOverlayWidget);
            setLayout(layout);
            mOverlayWidget->setMessageString("Application -> Start Rendering");
              
        }
    #else
        Widget::Widget() 
        {
            
        }
    #endif
            
        
    
    //-------------------------------------------------------------------------------------
    Widget::~Widget(void)
    {
    }
    
    //-------------------------------------------------------------------------------------
    bool Widget::configure(void)
    {
        // Show the configuration dialog and initialise the system
        // You can skip this and use root.restoreConfig() to load configuration
        // settings if you were sure there are valid ones saved in ogre.cfg
    
        Ogre::String widgetHandle = Ogre::StringConverter::toString((size_t)((HWND)this->winId()));
        Ogre::NameValuePairList  viewConfig;
        viewConfig["externalWindowHandle"] = widgetHandle;
        // The line below utilizes the root's timer in order to generate a unique name for each widget instance
        mWindow = mRoot->createRenderWindow(Ogre::StringConverter::toString(mRoot->getTimer()->getMicroseconds()),
    		width(), height(), false, &viewConfig);
        return true;
    }
    //-------------------------------------------------------------------------------------
    void Widget::chooseSceneManager(void)
    {
        // Get the SceneManager, in this case a generic one
        mOverlayWidget->setMessageString("Creating Scene Manager");
        mSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC);
    }
    //-------------------------------------------------------------------------------------
    void Widget::createCamera(void)
    {
        mOverlayWidget->setMessageString("Creating Camera");
        // Create the camera
        mCamera = mSceneMgr->createCamera(Ogre::StringConverter::toString(mRoot->getTimer()->getMicroseconds()));
    
        // Position it at 500 in Z direction
        mCamera->setPosition(Ogre::Vector3(0,0,80));
        // Look back along -Z
        mCamera->lookAt(Ogre::Vector3(0,0,-300));
        mCamera->setNearClipDistance(0.1);
        mCameraMan = new QOgre::CameraMan(mCamera);
    }
    //-------------------------------------------------------------------------------------
    QPaintEngine* Widget::paintEngine() const
    {
        // We don't want another paint engine to get in the way for our Ogre based paint engine.
        // So we return nothing.
        return NULL;
    }
    //-------------------------------------------------------------------------------------
    void Widget::destroyScene(void)
    {
    }
    //-------------------------------------------------------------------------------------
    void Widget::createViewports(void)
    {
        // Create one viewport, entire window
        Ogre::Viewport* vp = mWindow->addViewport(mCamera);
        vp->setBackgroundColour(Ogre::ColourValue(0,0,0));
    
        // Alter the camera aspect ratio to match the viewport
        mCamera->setAspectRatio(
    	Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight()));
    
        mOverlayWidget->setMessageString("Creating viewports...");
    }
    //-------------------------------------------------------------------------------------
    void Widget::setupResources(void)
    {
        // Load resource paths from config file
        Ogre::ConfigFile cf;
        cf.load(mResourcesCfg);
        mOverlayWidget->setMessageString("Loading resource paths from \n" + QString::fromStdString(mResourcesCfg));
        // Go through all sections & settings in the file
        Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
    
        Ogre::String secName, typeName, archName;
        while (seci.hasMoreElements())
        {
    	secName = seci.peekNextKey();
    	Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
    	Ogre::ConfigFile::SettingsMultiMap::iterator i;
    	for (i = settings->begin(); i != settings->end(); ++i)
    	{
    	    typeName = i->first;
    	    archName = i->second;
    	    Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
    		archName, typeName, secName);
    	    mOverlayWidget->setMessageString("Loading resource section '"
    					     + QString::fromStdString(secName)
    					     + "' (" + QString::fromStdString(typeName) + ")");
    	}
        }
    }
    //-------------------------------------------------------------------------------------
    void Widget::createResourceListener(void)
    {
    
    }
    //-------------------------------------------------------------------------------------
    void Widget::paintEvent(QPaintEvent *e)
    {
    
    }
    //-------------------------------------------------------------------------------------
    void Widget::resizeEvent(QResizeEvent *e)
    {
        if(e->isAccepted())
        {
    	const QSize &newSize = e->size();
    	if(mRoot && mCamera)
    	{
    	    mWindow->resize(newSize.width(), newSize.height());
    	    mWindow->windowMovedOrResized();
    
    	    Ogre::Real aspectRatio = Ogre::Real(newSize.width()) / Ogre::Real(newSize.height());
    	    mCamera->setAspectRatio(aspectRatio);
    	}
        }
    }
    //-------------------------------------------------------------------------------------
    void Widget::mouseMoveEvent(QMouseEvent *e)
    {
        if (mSystemInitialized)
        {
    	Ogre::Vector2 oldPos = mAbsolute;
    	mAbsolute = Ogre::Vector2(e->pos().x(), e->pos().y());
    	mRelative = mAbsolute - oldPos;
    	mCameraMan->injectMouseMove(mRelative);
        }
    }
    
    //-------------------------------------------------------------------------------------
    void Widget::mousePressEvent(QMouseEvent *e)
    {
        if (mSystemInitialized)
    	mCameraMan->injectMouseDown(e);
    }
    
    //-------------------------------------------------------------------------------------
    void Widget::mouseReleaseEvent(QMouseEvent *e)
    {
        if (mSystemInitialized)
    	mCameraMan->injectMouseUp(e);
    }
    //-------------------------------------------------------------------------------------
    void Widget::wheelEvent(QWheelEvent *e)
    {
        if (mSystemInitialized)
    	mCameraMan->injectMouseWheel(e);
    }
    
    //-------------------------------------------------------------------------------------
    void Widget::keyPressEvent(QKeyEvent *e)
    {
        if (mSystemInitialized)
    	mCameraMan->injectKeyDown(e);
    }
    
    //-------------------------------------------------------------------------------------
    void Widget::keyReleaseEvent(QKeyEvent *e)
    {
        if (mSystemInitialized)
    	mCameraMan->injectKeyUp(e);
    }
    //-------------------------------------------------------------------------------------
    void Widget::updateOgre(float timeSinceLastFrame)
    {
        mTimeSinceLastFrame = timeSinceLastFrame;
        repaint();
        if (this->size() != this->parentWidget()->size())
    	resize(this->parentWidget()->size());
    }
    
    //-------------------------------------------------------------------------------------
    bool Widget::updateExternalSystems()
    {
        return true;
    }
    
    //-------------------------------------------------------------------------------------
    void Widget::loadResources(void)
    {
        Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
    }
    
    //-------------------------------------------------------------------------------------
    void Widget::go(Ogre::Root* root, Ogre::SceneManager* mgr)
    {
    #ifdef _DEBUG
        mResourcesCfg = "resources_d.cfg";
        mPluginsCfg = "plugins_d.cfg";
    #else
        mResourcesCfg = "resources.cfg";
        mPluginsCfg = "plugins.cfg";
    #endif
    
        mRoot = root;
        if (mgr)
        {
            mSceneMgr = mgr;
            mPassedSM = true;
        }
    
        if (!setup())
    	return;
    
        // clean up
        destroyScene();
    }
    //-------------------------------------------------------------------------------------
    bool Widget::setup(void)
    {
        setupResources();
    
        bool carryOn = configure();
        if (!carryOn) return false;
    
        if (!mSceneMgr)
    	chooseSceneManager();
        createCamera();
        createViewports();
    
        // Set default mipmap level (NB some APIs ignore this)
        Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
        // Create any resource listeners (for loading screens)
        createResourceListener();
    
        // Load resources
        loadResources();
    
        mSystemInitialized = true;
        mOverlayWidget->hide();
    
        if (!mPassedSM)
        createScene();
    
        return true;
    }
    //-------------------------------------------------------------------------------------
    void Widget::createScene(void)
    {
        mOverlayWidget->setMessageString("Creating Scene");
        // create our model, give it the shader material, and place it at the origin
        Ogre::Entity *ent = mSceneMgr->createEntity("The Big Head", "ogrehead.mesh");
        Ogre::SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode();
        node->attachObject(ent);
    
        mCameraMan->setTarget(ent->getParentSceneNode());
    
        mCamera->setFixedYawAxis(true);
        // Set ambient light
        mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));
    
        // Create a light
        Ogre::Light* l = mSceneMgr->createLight("MainLight");
        l->setPosition(20,80,50);
        Ogre::ColourValue blender	    = Ogre::ColourValue(0.223529, 0.223529, 0.223529, 1.0);
        Ogre::ColourValue top	    = Ogre::ColourValue(0.224, 0.224, 0.224, 1.0);
        Ogre::ColourValue bottom	    = Ogre::ColourValue(50 / 255.0f, 50 / 255.0f, 50 / 255.0f, 1.0);
        setViewportBackground(blender, blender);
    }
    //-------------------------------------------------------------------------------------
    void Widget::setViewportBackground(Ogre::ColourValue top, Ogre::ColourValue bottom)
    {
        // Create background material
        Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create("Background", "General");
        material->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false);
        material->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false);
        material->getTechnique(0)->getPass(0)->setLightingEnabled(false);
    
        // Create background rectangle covering the whole screen
        QOgre::ColouredRectangle2D* rect = new QOgre::ColouredRectangle2D();
        rect->setCorners(-1.0, 1.0, 1.0, -1.0);
        rect->setMaterial("Background");
    
        // Set the colours
        rect->setColours(top, bottom, top, bottom);
    
        // Render the background before everything else
        rect->setRenderQueueGroup(Ogre::RENDER_QUEUE_BACKGROUND);
    
        // Use infinite AAB to always stay visible
        Ogre::AxisAlignedBox aabInf;
        aabInf.setInfinite();
        rect->setBoundingBox(aabInf);
    
        // Attach background to the scene
        Ogre::SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Background");
        node->attachObject(rect);
    }
    //-------------------------------------------------------------------------------------
    Code:
     
    ../../../../QT/Qt5.2.1_mingw32/QtSDK-i686/include/QtWidgets/qwidget.h: In copy constructor 'QOgre::Widget::Widget(const QOgre::Widget&)':
    ../../../../QT/Qt5.2.1_mingw32/QtSDK-i686/include/QtWidgets/qwidget.h:728:20: error: 'QWidget::QWidget(const QWidget&)' is private
         Q_DISABLE_COPY(QWidget)
                        ^
    ../../../../QT/Qt5.2.1_mingw32/QtSDK-i686/include/QtCore/qglobal.h:978:5: note: in definition of macro 'Q_DISABLE_COPY'
         Class(const Class &) Q_DECL_EQ_DELETE;\
         ^
    In file included from ../../../../QtOgre/mainwindow.h:13:0,
                     from ../../../../QtOgre/Main.cpp:11:
    e:/QtOgre/Widget.h:44:12: error: within this context

    Does anyone have any ideas why the compilation fails.
    I am informed that the copy constructor of QWidget is disabled.
    But still have no ideas how to fix it.
    Thanks
    Jack
    Last edited by lucky6969b; May 11th, 2014 at 03:41 PM.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Cannot compile a QT project using mingw32

    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured