Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Law

Pages: 1 [2] 3 4 5
16
Graphics / Re: Qt & SFML
« on: October 01, 2015, 05:00:38 pm »
Thank you for taking the time to break it down for me.

It does seem that I'm out of luck. I have other computers (all Windows) at my disposal, but I would have to install everything (Qt, SFML, something that compiles C++ could be useful as well). Not to mention, I'm now used to Ubuntu and have gotten quite unfamiliar with Windows and C++ compilation in general. I think I'm going to use a laptop I have, install Ubuntu 15.04 on it and see how this plays out.

As a matter of fact, I have already encountered several un-explainable Qt problems with the computer I'm currently using. Qt::AlignJustify doesn't work for no reason, for instance. I've never had any problems with SFML though, as a result I've always assumed that most of my problems were due to Qt, not due to my computer. It's strange in a way because I chose 14.04 LTS, over the regular version of Ubuntu, to avoid silly problems, precisely.

I suppose I'll update my status in the near future :)

17
Graphics / Re: Qt & SFML
« on: October 01, 2015, 04:04:21 pm »
So, what should I do? Is there some specific package that I should have installed? Program also seems to block at _XSend():

#0  0x00007ffff7ae0dab in _XSend () from /usr/lib/x86_64-linux-gnu/libX11.so.6
#1  0x00007ffff7ae1089 in _XReadEvents () from /usr/lib/x86_64-linux-gnu/libX11.so.6
#2  0x00007ffff7ac9777 in XIfEvent () from /usr/lib/x86_64-linux-gnu/libX11.so.6
#3  0x00007ffff7b00525 in ?? () from /usr/lib/x86_64-linux-gnu/libX11.so.6
#4  0x00007ffff7b023f6 in _XimProtoOpenIM () from /usr/lib/x86_64-linux-gnu/libX11.so.6
#5  0x00007ffff7b067e8 in _XimOpenIM () from /usr/lib/x86_64-linux-gnu/libX11.so.6
#6  0x00007ffff743a851 in sf::priv::WindowImplX11::WindowImplX11(unsigned long) () from /usr/local/lib/libsfml-window.so.2.3
#7  0x00007ffff7430211 in sf::priv::WindowImpl::create(unsigned long) () from /usr/local/lib/libsfml-window.so.2.3
#8  0x00007ffff742fe5e in sf::Window::create(unsigned long, sf::ContextSettings const&) () from /usr/local/lib/libsfml-window.so.2.3
#9  0x00000000004d5329 in QSFMLCanvas::showEvent (this=0x160df80) at QSFMLCanvas.cpp:39
#10 0x00007ffff62942a7 in QWidget::event (this=0x160df80, event=0x7fffffffdc10) at kernel/qwidget.cpp:8161
#11 0x00007ffff6258c8c in QApplicationPrivate::notify_helper (this=this@entry=0x1192ba0, receiver=receiver@entry=0x160df80, e=e@entry=0x7fffffffdc10) at kernel/qapplication.cpp:3486
#12 0x00007ffff625de56 in QApplication::notify (this=0x7fffffffdd20, receiver=0x160df80, e=0x7fffffffdc10) at kernel/qapplication.cpp:3236
#13 0x00007ffff5692c2d in QCoreApplication::notifyInternal (this=0x7fffffffdd20, receiver=receiver@entry=0x160df80, event=event@entry=0x7fffffffdc10) at kernel/qcoreapplication.cpp:881
#14 0x00007ffff629157e in sendEvent (event=0x7fffffffdc10, receiver=0x160df80) at ../../include/QtCore/../../src/corelib/kernel/qcoreapplication.h:232
#15 QWidgetPrivate::show_helper (this=this@entry=0x160e330) at kernel/qwidget.cpp:7164
#16 0x00007ffff629367a in QWidget::setVisible (this=0x160df80, visible=<optimized out>) at kernel/qwidget.cpp:7376
#17 0x000000000058cd8c in main (argc=1, argv=0x7fffffffdf18) at Menu.cpp:39

18
Graphics / Re: Qt & SFML
« on: September 29, 2015, 01:54:49 pm »
Oh, well as I mentioned in post 6, I commented the XFlush thing because I thought I didn't need it (and also because I couldn't manage to find the right libraries and compile it). That might be the root of my problem then. I'm using Ubuntu 14.04 LTS.

The headers of QSFMLCanvas.cpp are now:
#include "QSFMLCanvas.hpp"
#include <QX11Info>
#include <X11/Xlib.h>
#include <iostream>

I uncommented the XFlush line and everything compiles just fine. When I execute the program though, I have the same problems. I'm going to check if the packages are up to date like binary said.

I updated everything and still have the problem :(

My current QSFMLCanvas.cpp file:
#include "QSFMLCanvas.hpp"
#include <QX11Info>
#include <X11/Xlib.h>
#include <iostream>

QSFMLCanvas::QSFMLCanvas(QWidget* Parent, const QPoint& Position, const QSize& Size, unsigned int FrameTime) :
        QWidget(Parent),
        myInitialized(false)
{
        // Setup some states to allow direct rendering into the widget
        setAttribute(Qt::WA_PaintOnScreen);
        setAttribute(Qt::WA_OpaquePaintEvent);
        setAttribute(Qt::WA_NoSystemBackground);
        // Set strong focus to enable keyboard events to be received
        setFocusPolicy(Qt::StrongFocus);
        // Setup the widget geometry
        move(Position);
        resize(Size);
        // Setup the timer
        myTimer.setInterval(FrameTime);
}

QSFMLCanvas::QSFMLCanvas(void)
{
}

QSFMLCanvas::~QSFMLCanvas(void)
{
}

void QSFMLCanvas::showEvent(QShowEvent*)
{
        if (not myInitialized)
        {
                // Under X11, we need to flush the commands sent to the server to ensure that
                // SFML will get an updated view of the windows
                XFlush(QX11Info::display());
                // Create the SFML window with the widget handle
                RenderWindow::create(static_cast<sf::WindowHandle>(winId()));
                // Let the derived class do its specific stuff
                OnInit();
                // Setup the timer to trigger a refresh at specified framerate
                connect(&myTimer, SIGNAL(timeout()), this, SLOT(repaint()));
                myTimer.start();
                myInitialized = true;
        }
       
        std::cout << "show event" << std::endl;
}

QPaintEngine* QSFMLCanvas::paintEngine(void) const
{
        std::cout << "paint engine" << std::endl;
        return 0;
}

void QSFMLCanvas::paintEvent(QPaintEvent*)
{
        // Let the derived class do its specific stuff
        OnUpdate();
        // Display on screen
        RenderWindow::display();
       
        std::cout << "paint event" << std::endl;
}
void QSFMLCanvas::OnInit(void)
{
}

void QSFMLCanvas::OnUpdate(void)
{
}

The std::cout lines are never reached.

19
Graphics / Re: Qt & SFML
« on: September 28, 2015, 08:34:26 pm »
I'm not sure if I did the right thing, but I step 1000'ed until the program blocked, then interrupted it and where'd:

(gdb) where
#0  0x00007ffff3e5f089 in _XReadEvents () from /usr/lib/x86_64-linux-gnu/libX11.so.6
#1  0x00007ffff3e47777 in XIfEvent () from /usr/lib/x86_64-linux-gnu/libX11.so.6
#2  0x00007ffff3e7e525 in ?? () from /usr/lib/x86_64-linux-gnu/libX11.so.6
#3  0x00007ffff3e803f6 in _XimProtoOpenIM () from /usr/lib/x86_64-linux-gnu/libX11.so.6
#4  0x00007ffff3e847e8 in _XimOpenIM () from /usr/lib/x86_64-linux-gnu/libX11.so.6
#5  0x00007ffff776f851 in sf::priv::WindowImplX11::WindowImplX11(unsigned long) () from /usr/local/lib/libsfml-window.so.2.3
#6  0x00007ffff7765211 in sf::priv::WindowImpl::create(unsigned long) () from /usr/local/lib/libsfml-window.so.2.3
#7  0x00007ffff7764e5e in sf::Window::create(unsigned long, sf::ContextSettings const&) () from /usr/local/lib/libsfml-window.so.2.3
#8  0x00000000004d525c in QSFMLCanvas::showEvent (this=0x160e2b0) at QSFMLCanvas.cpp:39
#9  0x00007ffff67cd2a7 in QWidget::event (this=0x160e2b0, event=0x7fffffffdc10) at kernel/qwidget.cpp:8161
#10 0x00007ffff6791c8c in QApplicationPrivate::notify_helper (this=this@entry=0x1192ba0, receiver=receiver@entry=0x160e2b0, e=e@entry=0x7fffffffdc10) at kernel/qapplication.cpp:3486
#11 0x00007ffff6796e56 in QApplication::notify (this=0x7fffffffdd20, receiver=0x160e2b0, e=0x7fffffffdc10) at kernel/qapplication.cpp:3236
#12 0x00007ffff5bcbc2d in QCoreApplication::notifyInternal (this=0x7fffffffdd20, receiver=receiver@entry=0x160e2b0, event=event@entry=0x7fffffffdc10) at kernel/qcoreapplication.cpp:881
#13 0x00007ffff67ca57e in sendEvent (event=0x7fffffffdc10, receiver=0x160e2b0) at ../../include/QtCore/../../src/corelib/kernel/qcoreapplication.h:232
#14 QWidgetPrivate::show_helper (this=this@entry=0x160e660) at kernel/qwidget.cpp:7164
#15 0x00007ffff67cc67a in QWidget::setVisible (this=0x160e2b0, visible=<optimized out>) at kernel/qwidget.cpp:7376
#16 0x000000000058cc7e in main (argc=1, argv=0x7fffffffdf18) at Menu.cpp:39

20
Graphics / Re: Qt & SFML
« on: September 28, 2015, 07:11:12 pm »
Quote
My application doesn't block at startup if I give up using the method show.
I already know that, this is not what I asked.
In this case there is no blocking. I see another blank window when I execute the program.

21
Graphics / Re: Qt & SFML
« on: September 28, 2015, 05:09:25 pm »
My application doesn't block at startup if I give up using the method show.
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    WindowFrame::SFMLFrame = std::make_shared<QFrame>();
    WindowFrame::SFMLFrame->setWindowTitle("Qt SFML");
    WindowFrame::SFMLFrame->resize(GS::resWidth, GS::resHeight);
    WindowFrame::SFMLFrame->show();
   
    WindowFrame::SFMLWindow = std::make_shared<MyCanvas>(WindowFrame::SFMLFrame.get(), QPoint(0, 0), QSize(GS::resWidth, GS::resHeight));
    WindowFrame::SFMLWindow->show(); // blocks here
   
    return app.exec();
}

The following code doesn't block at all:
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    WindowFrame::SFMLFrame = std::make_shared<QFrame>();
    WindowFrame::SFMLFrame->setWindowTitle("Qt SFML");
    WindowFrame::SFMLFrame->resize(GS::resWidth, GS::resHeight);
    WindowFrame::SFMLFrame->show();
   
    WindowFrame::SFMLWindow = std::make_shared<MyCanvas>(WindowFrame::SFMLFrame.get(), QPoint(0, 0), QSize(GS::resWidth, GS::resHeight));
    //WindowFrame::SFMLWindow->show();
   
    return app.exec();
}
(... but the window is kept blank indefinitely.)

The following code doesn't block at all as well, but no window shows up:
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    WindowFrame::SFMLFrame = std::make_shared<QFrame>();
    WindowFrame::SFMLFrame->setWindowTitle("Qt SFML");
    WindowFrame::SFMLFrame->resize(GS::resWidth, GS::resHeight);
    //WindowFrame::SFMLFrame->show();
   
    WindowFrame::SFMLWindow = std::make_shared<MyCanvas>(WindowFrame::SFMLFrame.get(), QPoint(0, 0), QSize(GS::resWidth, GS::resHeight));
    WindowFrame::SFMLWindow->show();
   
    return app.exec();
}

Now, in either of these last two codes, if I later try to show the other widget (that is, WindowFrame::SFMLFrame for the third code, and WindowFrame::SFMLWindow for the second code) by pressing a QPushButton that is connected to a function that calls the show method, the program blocks just like it does in the first code.

22
Graphics / Re: Qt & SFML
« on: September 28, 2015, 02:58:33 pm »
Before trying to integrate SFML into a Qt GUI, did you first learn Qt alone? Have you already successfully created a GUI without SFML?
Absolutely, I actually had a Qt project and an SFML project, now I'm simply merging them and trying to integrate the SFML project into the Qt one. Compilation is no longer a problem, execution is.

23
Graphics / Re: Qt & SFML
« on: September 28, 2015, 01:46:46 pm »
First, what do you want to do? The canvas is parented to the frame, but isn't inserted in it (with a layout for example). Or do you want two independant top-level windows?

Then you could simply use your debugger to find out where your program is blocked exactly (in which Qt call).
Thanks for your reply.

I don't understand, is there any need for Layouts? Either it's an oversight, or the tutorial I used didn't use any. I just gave the pointer of the Frame as the first parameter of the MyCanvas constructor:

WindowFrame::SFMLWindow = std::make_shared<MyCanvas>(WindowFrame::SFMLFrame.get(), QPoint(0, 0), QSize(GS::resWidth, GS::resHeight));

I've never managed to use the debugger under Ubuntu, so I'd rather try out any other ways to solve this issue first :S

24
Graphics / Re: Qt & SFML
« on: September 27, 2015, 07:18:58 pm »
Well I understand that reading through the code isn't really interesting, so everybody's busy doing something else. But if I can't even get hints or methods on how to solve the problem myself, I really don't know where to go. I'm pretty sure the problem is basic though, as I've rarely had complicated problems in coding so far.

25
Graphics / Re: Qt & SFML
« on: September 25, 2015, 06:35:13 pm »
Help please. I can't seem to use show() without the entire program blocking. I've also injected

std::cout << "foo" << std::endl;

to see if any of the following functions

virtual void showEvent(QShowEvent*);
virtual QPaintEngine* paintEngine(void) const;
virtual void paintEvent(QPaintEvent*);

from QSFMLCanvas were called, it seems they aren't for whatever reason. The same trick shows that the following functions

void OnInit(void);
void OnUpdate(void);

from MyCanvas are never called either.

I'm starting to wonder if I posted my problem in the correct section. Window might have been more accurate. Or maybe General.

26
Graphics / Re: Qt & SFML
« on: September 21, 2015, 04:32:24 pm »
Anyone know why calling QWidget::show() stalls the program? Also, how can I put my SFMLCanvas instance (SFMLWindow) in VideoMode without actually calling sf::RenderWindow::create(), which seems to stall the program as well ?

27
Graphics / Re: Qt & SFML
« on: September 18, 2015, 01:58:15 pm »
You mean would right? Anyway I hear that using std::threads is very nasty for these things, so I'd rather avoid them for now.

I would really, really appreciate if someone could take the time to help me out here. I don't want to be a pain and bump this thread every day or so.

Addendum: I've just realized that the code in my main function has a mistake. It should be
    WindowFrame::SFMLWindow = std::make_shared<MyCanvas>(WindowFrame::SFMLFrame.get(), QPoint(0, 0), QSize(GS::resWidth, GS::resHeight));
    WindowFrame::SFMLWindow->show();

not
    WindowFrame::SFMLWindow = std::make_shared<MyCanvas>(WindowFrame::SFMLFrame.get(), QPoint(0, 0), QSize(GS::resWidth, GS::resHeight));
    WindowFrame::SFMLFrame->show();

Once I corrected that, my program stalls at
    WindowFrame::SFMLWindow->show();

and doesn't even reach `app.exec()`

28
Graphics / Re: Qt & SFML
« on: September 18, 2015, 01:15:11 pm »
So I've actually tried the 1.6 tutorial. I wasn't aware that you couldn't launch an SFML Window out of nowhere when you're already using Qt.

QSFMLCanvas.hpp
#pragma once

#include <QTimer>
#include <QWidget>
#include <SFML/Graphics.hpp>

class QSFMLCanvas : public QWidget, public sf::RenderWindow
{
        private:
       
                QTimer myTimer;
                bool myInitialized;
       
        public:
       
                explicit QSFMLCanvas(QWidget*, const QPoint&, const QSize&, unsigned int = 0);
                QSFMLCanvas(void);
                virtual ~QSFMLCanvas(void);
               
                virtual void showEvent(QShowEvent*);
                virtual QPaintEngine* paintEngine(void) const;
                virtual void paintEvent(QPaintEvent*);
                virtual void OnInit(void);
                virtual void OnUpdate(void);
};

QSFMLCanvas.cpp (not using X11... I mean, if I were using this, I would know right?)
#include <iostream>

#include "QSFMLCanvas.hpp"

QSFMLCanvas::QSFMLCanvas(QWidget* Parent, const QPoint& Position, const QSize& Size, unsigned int FrameTime) :
        QWidget(Parent),
        myInitialized (false)
{
        // Setup some states to allow direct rendering into the widget
        setAttribute(Qt::WA_PaintOnScreen);
        setAttribute(Qt::WA_OpaquePaintEvent);
        setAttribute(Qt::WA_NoSystemBackground);
        // Set strong focus to enable keyboard events to be received
        setFocusPolicy(Qt::StrongFocus);
        // Setup the widget geometry
        move(Position);
        resize(Size);
        // Setup the timer
        myTimer.setInterval(FrameTime);
}

QSFMLCanvas::QSFMLCanvas(void)
{
}

QSFMLCanvas::~QSFMLCanvas(void)
{
}

void QSFMLCanvas::showEvent(QShowEvent*)
{
        if (not myInitialized)
        {
                // Under X11, we need to flush the commands sent to the server to ensure that
                // SFML will get an updated view of the windows
                //XFlush(QX11Info::display());
                // Create the SFML window with the widget handle
                RenderWindow::create(static_cast<sf::WindowHandle>(winId()));
                // Let the derived class do its specific stuff
                OnInit();
                // Setup the timer to trigger a refresh at specified framerate
                connect(&myTimer, SIGNAL(timeout()), this, SLOT(repaint()));
                myTimer.start();
                myInitialized = true;
        }
}

QPaintEngine* QSFMLCanvas::paintEngine(void) const
{
        return 0;
}

void QSFMLCanvas::paintEvent(QPaintEvent*)
{
        // Let the derived class do its specific stuff
        OnUpdate();
        // Display on screen
        RenderWindow::display();
}
void QSFMLCanvas::OnInit(void)
{
}

void QSFMLCanvas::OnUpdate(void)
{
}

MyCanvas.hpp
#pragma once

#include <SFML/Graphics.hpp>
#include "QSFMLCanvas.hpp"

class MyCanvas : public QSFMLCanvas
{
        private:
       
                sf::Clock myClock;
                sf::Texture myImage;
                sf::Sprite mySprite;

        public:
       
                MyCanvas(QWidget*, const QPoint&, const QSize&);
                MyCanvas(void);
                ~MyCanvas(void);
               
                void OnInit(void);
                void OnUpdate(void);
};

MyCanvas.cpp
#include <iostream>
#include <QDir>
#include <string>

#include "MyCanvas.hpp"

MyCanvas::MyCanvas(QWidget* Parent, const QPoint& Position, const QSize& Size) : QSFMLCanvas(Parent, Position, Size)
{
}

MyCanvas::MyCanvas(void)
{
}

MyCanvas::~MyCanvas(void)
{
}

void MyCanvas::OnInit(void)
{
        // Load the image
        std::cout << "onInit" << std::endl;
        QString dir = QDir::currentPath();
        std::string utf8_text = dir.toUtf8().constData();
        std::cout << "HELLO: " << utf8_text << std::endl;
       
        if (not myImage.loadFromFile(utf8_text + "/chef.png"))
                std::cout << "Loading error"<< std::endl;
        else
                std::cout << "Image was loaded fine" << std::endl;
       
        // Setup the sprite
        mySprite.setTexture(myImage);
        mySprite.setPosition(150, 150);
        std::cout << "setting the texture of the sprite" << std::endl;
        //mySprite.setCenter(mySprite.GetSize() / 2.f);
        myClock.restart();
}

void MyCanvas::OnUpdate(void)
{
        // Clear screen
        RenderWindow::clear(sf::Color(0, 128, 0));
        // Rotate the sprite
        mySprite.rotate(myClock.getElapsedTime().asSeconds() * 100.f);
        // Draw it
        RenderWindow::draw(mySprite);
        myClock.restart();
}

The QFrame and MyCanvas instances are defined as public static std::shared_ptr of some class:
class WindowFrame : public QObject
{
        Q_OBJECT

                // ...
       
        public:
       
                static std::shared_ptr<QFrame>                          SFMLFrame;
                static std::shared_ptr<MyCanvas>                        SFMLWindow;
               
                WindowFrame(void);
                ~WindowFrame(void);

                // ...
};

Now, here's what my main function looks like:
int main(int argc, char *argv[])
{
        QApplication app(argc, argv);

        WindowFrame::SFMLFrame = std::make_shared<QFrame>();
        WindowFrame::SFMLFrame->setWindowTitle("Qt SFML");
        WindowFrame::SFMLFrame->resize(GS::resWidth, GS::resHeight);
        WindowFrame::SFMLFrame->show();
       
        WindowFrame::SFMLWindow = std::make_shared<MyCanvas>(WindowFrame::SFMLFrame.get(), QPoint(0, 0), QSize(GS::resWidth, GS::resHeight));
        WindowFrame::SFMLFrame->show();
       
        // stuff irrelevant to SFML
        return app.exec();
}

But I still have the same problem as before... The following line is stalled indefinitely, when I press a QPushButton that causes its execution:
WindowFrame::SFMLWindow->sf::RenderWindow::create(sf::VideoMode(GS::resWidth, GS::resHeight), "Some Window :D");

So, what am I doing wrong in all this? Is there nothing too redundant in doing:
WindowFrame::SFMLFrame->resize(GS::resWidth, GS::resHeight);
// ...
WindowFrame::SFMLWindow = std::make_shared<MyCanvas>(WindowFrame::SFMLFrame.get(), QPoint(0, 0), QSize(GS::resWidth, GS::resHeight));

Thank you in advance.

29
Graphics / Re: Qt & SFML
« on: September 15, 2015, 07:57:08 pm »
Does the line work in a standalone program without Qt? Maybe there's something incompatible or wrong with your build environment.
Yes, I'm actually merging my SFML project with my Qt project, and the former project was working well before.

Well, even during QApplication::exec, it is possible to create non-Qt windows, right? I mean, nothing in the part of my project that is related to SFML, inherits from QWidget.

30
Graphics / Re: Qt & SFML
« on: September 15, 2015, 07:04:36 pm »
Quote
the program fizzles
I have no idea what this means :P

Do you have an event loop for your window?
Oh, I only meant that if I print a foo right before, and a foo right after this line, I only get one foo. Yes there's a loop, but my program seems to take infinite time to get past this line, so I never reach the while loop.

Pages: 1 [2] 3 4 5
anything