Phenixo
Phenixo

Reputation: 31

SDL with Qtcrator

I have used qtcreator for console application. Now I want to use it with SDL1 because I have a tutorial on SDL1 and I want to learn SDL on qtcreator but it seems that qtcreator have 2 option first consol application second the interface and window application using qt. So Can I use the window generated with SDL. I did same research and I have add the SDL library to qmake but it didn’t work

my file *.pro

    TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt


LIBS += -L C:/Qt/Tools/SDL/SDL1/lib -lmingw32 -lSDLmain -lSDL -mwindows
INCLUDEPATH += C:/Qt/Tools/SDL/SDL1/include/

SOURCES += main.cpp

include(deployment.pri)
qtcAddDeployment()

my main.cpp

#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>

void pause();

int main(int argc, char *argv[])
{
    SDL_Init(SDL_INIT_VIDEO); // Initialisation de la SDL

    SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE); // Ouverture de la fenêtre

    pause(); // Mise en pause du programme

    SDL_Quit(); // Arrêt de la SDL

    return EXIT_SUCCESS; // Fermeture du programme
}

void pause()
{
    int continuer = 1;
    SDL_Event event;

    while (continuer)
    {
        SDL_WaitEvent(&event);
        switch(event.type)
        {
            case SDL_QUIT:
                continuer = 0;
        }
    }
}

I have this error

 C:\Users\Phenix\Documents\c++ project\td7\test3\main.cpp:7: avertissement : unused parameter 'argc' [-Wunused-parameter]  int main(int argc, char *argv[])
    C:\Users\Phenix\Documents\c++ project\td7\test3\main.cpp:7: avertissement : unused parameter 'argv' [-Wunused-parameter]    int main(int argc, char *argv[])
    crt0_c.c:-1: erreur : undefined reference to `WinMain@16'
    collect2.exe:-1: erreur : error: ld returned 1 exit status

And This is my SDL1 directory there is more file in the end of the directory but I think they are not important

Test
Share
Man 
Lib
Include
Docs
Build-scripts
bin

Thanks a lot for helping me

Upvotes: 2

Views: 468

Answers (2)

Phenixo
Phenixo

Reputation: 31

I have found a solution this is my finale *.pro file

    TEMPLATE = app
CONFIG += console  # supprime cette ligne si t'as pas envie de voir de console lors de l'execution du programme
CONFIG -= app_bundle
CONFIG -= qt

LIBS += -L C:/Qt/Tools/SDL/SDL1/lib -lSDL -lSDLmain
INCLUDEPATH += C:/Qt/Tools/SDL/SDL1/include/



win32:QMAKE_LIBS_QT_ENGTRY -= -lqtmain
win32-g++:DEFINES -=QT_NEEDS_QMAIN

QMAKE_LFLAGS += -lmingw32 -lSDLmain -lSDL -mwindows
QMAKE_LINK +=-lmingw32 -lSDLmain -lSDL -mwindows
SOURCES += main.cpp

I didn't add the SDL.dll file in to SysWOW64. you have to add if the compilation showing no error but the window doesn’t open.

Upvotes: 0

legends2k
legends2k

Reputation: 32884

qtcreator have 2 option first consol application second the interface and window application using qt. So Can I use the window generated with SDL

You should choose console application now too, since choosing the second option of Window application using Qt means you'll have to use Qt framework to create the window and not SDL which is what you intend to.

Choose the console option and the error should go away too; since for the latter option of using Qt, you're supposed to provide qMain and not main that's usual for ordinary C++ programs.

Since you're using MinGW, you can pass -mwindows flag to the linker to get rid of the additional console window that would be shown when you launch the application along with the SDL window.

Upvotes: 0

Related Questions