Jump to content

  • Log In with Google      Sign In   
  • Create Account


QT SFML C++


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
27 replies to this topic

#1 Saint Squireen   Members   -  Reputation: 181

Like
0Likes
Like

Posted 20 July 2012 - 12:42 PM

I have been trying to figure out how to sync/link SFML and QT together by making a custom widget and following the advice on the tutorials page of

http://www.sfml-dev.org/tutorials/1.3/graphics-qt.php

and I just dont understand it. Ive never tried to make a custom widget before and I apparently cant wrap my mind around whats being shown and what I need to do.

Could somebody please try to help me understand this?

~Saint Squireen

Sponsor:

#2 Servant of the Lord   Crossbones+   -  Reputation: 18500

Like
0Likes
Like

Posted 20 July 2012 - 12:45 PM

You linked to the SFML 1.3 version tutorial. The latest stable version of SFML is 1.6, and the current officially unofficial build is version 2.0.
Which version of SFML are you actually using? Also, which version of Qt are you using? Most likely Qt would be either: 4.6.x, 4.7.x, 4.8.x, or (unofficial) 5.0.x.

Edited by Servant of the Lord, 20 July 2012 - 12:51 PM.

It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#3 Saint Squireen   Members   -  Reputation: 181

Like
0Likes
Like

Posted 20 July 2012 - 12:52 PM

Well i wanted to use SFML version 2.0 but I swapped that idea with the one to download and use SFML 1.6 for windows(64bit) because I think it will be much less riskier. Also I have never used SFML before. The QT that I have downloaded says it is 2.4.0 but thats not one of your acceptable answers so I dont have a clue. I have been working on QT for a very,VERY short amout of time.

~Saint Squireen

#4 Servant of the Lord   Crossbones+   -  Reputation: 18500

Like
2Likes
Like

Posted 20 July 2012 - 01:11 PM

The Qt you downloaded was probably the QtSDK 2.4.0 which is the version of QtCreator (I think?) but ships with the Qt api version 4.7.x or there-abouts, so you're fine.

If you are using SFML 1.6, you want to use this tutorial to be up to date.

Essentially, Qt and SFML are both two separate APIs, and gluing them together is definitely possible (my own game does that), but neither is designed with that in mind, which is why it may seem weird to you.

Do you understand C++ inheritance? The class being created in the SFML tutorial is inheriting a QWidget (from the Qt api) to override some virtual functions QWidget provides, so the new class can interact with the Qt API and other Qt widgets. The new class also inherits a sf::RenderWindow (from the SFML api) to allow SFML to control the drawing and input of that class, when Qt tells the class that it has input or that it is ready to draw.

Qt controls the lifetime of the widget, and calls the virtual functions, but SFML handles the virtual functions when called.
The class has to set some Qt-specific attributes to let Qt know that Qt itself won't be handling the drawing, among other things. Qt also uses something called Signals-and-Slots, which is a non-standard addition to C++. SFML takes advantage of that, to tell Qt to re-render the window at a specific framerate (this is the "connect(.., SIGNAL(...), ..., SLOT(...));" line of code.

Looking at the tutorial, is there a particular piece of code that you have questions about? There are a number of oddities in there, if you've never used Qt before.

Edited by Servant of the Lord, 20 July 2012 - 01:12 PM.

It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#5 Saint Squireen   Members   -  Reputation: 181

Like
0Likes
Like

Posted 20 July 2012 - 01:19 PM

First off, thanks for countinuously responding to my questions!!! And secondly, I do understand inheritance(at least I am pretty sure I do). I know what signal and slot do but from that point on (both in standard addition C++, SFML,QT)I know practically nothing else. Now Im just going to review the link you posted and Ill come back here in a couple minutes to update you. Thanks again!!!!!

~Saint Squireen

#6 Saint Squireen   Members   -  Reputation: 181

Like
0Likes
Like

Posted 20 July 2012 - 01:23 PM

Actually I do have a question, and this is probably the biggest and probably the noobiest/stupidest question ever:

Where do I make these projects or builds? :D

~Saint Squireen

#7 Servant of the Lord   Crossbones+   -  Reputation: 18500

Like
1Likes
Like

Posted 20 July 2012 - 01:36 PM

Using Qt Creator, to start a new project using the Qt API:
File -> New file or project -> Qt Widget Project -> Qt Gui Application

This will start a wizard to create a project.

First name your project and choose where to place the project, hit "Next" and on the "Target Setup" screen, select just two builds - one for release, and one for debug - using the same MinGW install and the same Qt api version.

The final page of the wizard sets up a Qt main window, and asks you to name it. The defaults are fine, but you can name it something different if you like. Uncheck "Generate form", if your SFML window is going to be your sole Qt window. Hit 'Next', and then the last page can be skipped if you're not using a version control system.

This will create an initial project, which includes your .pro file. Your .pro file is the makefile that QMake uses to compile your project.

It also creates a main.cpp, mainwindow.cpp, and mainwindow.h. Leave main.cpp as it is, but you can modify the 'MainWindow' class to be like the SFML tutorial describes, first changing:
//In the header:
#include <QtGui/QMainWindow>
class MainWindow : public QMainWindow
{
	Q_OBJECT
  
public:
	MainWindow(QWidget *parent = 0);
	~MainWindow();
};

//In the source file:
MainWindow::MainWindow(QWidget *parent)
	: QMainWindow(parent)
{
}

To this instead:
//In the header:
#include <QWidget> //I changed <QtGui/QMainWindow> to <QWidget>

class MainWindow : public QWidget //I changed QMainWindow to QWidget
{
	Q_OBJECT
  
public:
	MainWindow(QWidget *parent = 0);
	~MainWindow();
};

//In the source file:
MainWindow::MainWindow(QWidget *parent)
	: QWidget(parent) //I changed QMainWindow to QWidget
{
}

Then you can follow the tutorial for the SFML-specific tweaks.
In your .pro file, you need to add some variables: (this is in addition to the other variables already present in the .pro file)
#Location to save your executable:
DESTDIR = "../MyPath"

#Name of your executable:
TARGET = MyGame

#SFML libraries:
LIBS += -lsfml-audio -lsfml-graphics -lsfml-window -lsfml-system -lsfml-main

#Path to the linker import files: (sfml-audio.a or whatever)
LIBS += -L"D:/my/path/to/SFML/lib/"

#Path to SFML headers:
INCLUDEPATH = "D:/my/path/to/SFML/include/"

Edited by Servant of the Lord, 20 July 2012 - 01:41 PM.

It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#8 Cornstalks   Crossbones+   -  Reputation: 6974

Like
1Likes
Like

Posted 20 July 2012 - 01:55 PM

Well i wanted to use SFML version 2.0 but I swapped that idea with the one to download and use SFML 1.6 for windows(64bit) because I think it will be much less riskier.

For what it's worth, using SFML 2.0 is probably less risky than using 1.6, actually. Even though SFML 2.0 isn't technically "done," Laurent himself has said that SFML 1.6 is deprecated. It's ok if you go with 1.6 (the world will keep on revolving just fine), but I'd personally recommend upgrading to 2.0.
[ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

#9 Saint Squireen   Members   -  Reputation: 181

Like
0Likes
Like

Posted 20 July 2012 - 02:21 PM

Okay so I have just finished up word for word what you have done and did a bunch of copy and pasting. The only part I did not get, was when you said to look for SFML specific tweaks.... Could you clarify a little bit more? Also in that last picture of the variables that needed to go into my "project".pro class, is it okay if I copied the whole picture and pasted it into my "project".pro?

ps- Thanks so much again!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Posted Image

pps-Cornstalks-Thanks for the insight but I think I might just stick with 1.6 for now just to get started. Posted Image



ppps-I did nothing else to the project besides copy and paste what you said for me to do and my question now is, "what now?". Do I just save it? Do I just run it?

Edited by Saint Squireen, 20 July 2012 - 02:24 PM.


~Saint Squireen

#10 Servant of the Lord   Crossbones+   -  Reputation: 18500

Like
0Likes
Like

Posted 20 July 2012 - 02:32 PM

Well, did you follow the tutorial yet?

What I explained above was to get you to a starting place from which you can follow the tutorial. By "SFML-specific tweaks", I meant the tutorial SFML provides that walks through how to get SFML running with Qt. When following the tutorial, if you don't understand something, then let us know - but until you follow the tutorial, there's no point in us walking you through the exact same steps the tutorial walks you through, because the tutorial will do a superior job in explaining things. Posted Image

You're definitely welcome to copy+paste the .pro settings I showed you. Ofcourse, you have to fill in the details with what works for your environment, because "D:/my/path/to/SFML/lib/" doesn't actually exist on your computer. You have to replace it with the path to wherever you installed your copy of SFML's .a files. Same with "D:/my/path/to/SFML/include/" - that location doesn't actually exist, you have to replace it with the real location that is specific to where you installed SFML's header files.
It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#11 Saint Squireen   Members   -  Reputation: 181

Like
0Likes
Like

Posted 20 July 2012 - 02:37 PM

What should I do once I finish all of that up? Would I then build and run it?

~Saint Squireen

#12 Servant of the Lord   Crossbones+   -  Reputation: 18500

Like
0Likes
Like

Posted 20 July 2012 - 02:43 PM

Yep, and if there were no typos or other problems, and if everything links properly, you should see a basic SFML window that looks like any other SFML window, except it's controlled by Qt behind the scenes.
It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#13 Saint Squireen   Members   -  Reputation: 181

Like
0Likes
Like

Posted 20 July 2012 - 02:45 PM

By any chance would this same setup work for sfml 2.0 too?

~Saint Squireen

#14 Saint Squireen   Members   -  Reputation: 181

Like
0Likes
Like

Posted 20 July 2012 - 03:08 PM

Okay so I just fiished up everything and I only have one error left but I dont know what it means or how to solve it. It says:


multiple target patterns. stop.
File not found: Makefile.Debug


Do you know what it means?

~Saint Squireen

#15 Servant of the Lord   Crossbones+   -  Reputation: 18500

Like
0Likes
Like

Posted 20 July 2012 - 03:14 PM

By any chance would this same setup work for sfml 2.0 too?


It seems to be working fine (I just made the transfer yesterday and this morning).

With SFML 2.0, you probably need to compile it by source, and the tutorials aren't yet available for it. For learning purposes you'll want the tutorials to be exactly accurate. When you do move to SFML 2.0 on a different project, the API is mostly the same, but there are enough changes that you don't want to be following a tutorial and not know whether it's messing up because you did something wrong or because the API changed in that spot.

The transfer to SFML 2.0 for me only took a day, but I already know how to use SFML, and I haven't yet tested to make sure all the code is still working. I've already ran into one "gotcha" where everything compiles but doesn't work (easy to fix but tricky to find), and I'm sure there are a few more hidden away.

I'd recommend waiting for it to 2.0 to become officially release with complete tutorials, if you're trying to learn it at the same time.

On the other hand, SFML 2.0 is pretty much finished, and it's supposedly stable and cross-platform supporting already - it'll probably be official released real soon; a 'release client' was already released, so it'll probablly be officially released in a month or two. It's up to you to decide what makes the most sense for your learning process.

Edited by Servant of the Lord, 20 July 2012 - 03:26 PM.

It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#16 Servant of the Lord   Crossbones+   -  Reputation: 18500

Like
0Likes
Like

Posted 20 July 2012 - 03:15 PM

multiple target patterns. stop.
File not found: Makefile.Debug

Do you know what it means?


Copy+Paste your complete .pro file (between [ code ] and [ /code ] tags).
It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#17 Saint Squireen   Members   -  Reputation: 181

Like
0Likes
Like

Posted 20 July 2012 - 03:32 PM

Im sorry, but where?

~Saint Squireen

#18 Servant of the Lord   Crossbones+   -  Reputation: 18500

Like
0Likes
Like

Posted 20 July 2012 - 04:18 PM

In QtCreator, go to your .pro file. It'll be named after your project name: myProjectName.pro (Where 'myProjectName' is replaced with the name of your project)

Open it, select it all, and copy it. Then paste it here in a post.

Edited by Servant of the Lord, 20 July 2012 - 04:23 PM.

It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#19 Saint Squireen   Members   -  Reputation: 181

Like
0Likes
Like

Posted 20 July 2012 - 04:39 PM

hahahahahahahahahaha whoops sorry haha XD




#-------------------------------------------------
#
# Project created by QtCreator 2012-07-20T14:57:41
#
#-------------------------------------------------
QT += core gui
TARGET = SFML-Test
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
QSFMLCanvas.cpp
HEADERS += mainwindow.h \
QSFMLCanvas.hpp
FORMS += mainwindow.ui
#Location to save your executable:
DESTDIR = "C:\Users\Griffin Laptop\Desktop\SFML-1.6-sdk-windows-mingw.zip"
#Name of your executable:
TARGET = MyGame
#SFML libraries:
LIBS += -lsfml-audio -lsfml-graphics -lsfml-window -lsfml-system -lsfml-main
#Path to the linker import files: (sfml-audio.a or whatever)
LIBS += -L"C:\Users\Griffin Laptop\Desktop\SFML-1.6-sdk-windows-mingw.zip\SFML-1.6\lib"
#Path to SFML headers:
INCLUDEPATH = "C:\Users\Griffin Laptop\Desktop\SFML-1.6-sdk-windows-mingw.zip\SFML-1.6\include\SFML"

~Saint Squireen

#20 Servant of the Lord   Crossbones+   -  Reputation: 18500

Like
0Likes
Like

Posted 20 July 2012 - 05:23 PM

Change:
INCLUDEPATH = "C:\Users\Griffin Laptop\Desktop\SFML-1.6-sdk-windows-mingw.zip\SFML-1.6\include\SFML"
To:
INCLUDEPATH = "C:\Users\Griffin Laptop\Desktop\SFML-1.6-sdk-windows-mingw.zip\SFML-1.6\include\"

I don't know if your destination directory (DESTDIR) can be inside a zip file. I'd set it to a normal folder just for your project.
You also have 'TARGET' listed twice (with different assignments). Only have one.

That last one should fix your error, since the error is stating that you have too many TARGETs.
It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS