2

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

Martin G
  • 17,357
  • 9
  • 82
  • 98
Phenixo
  • 31
  • 4

2 Answers2

0

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.

legends2k
  • 31,634
  • 25
  • 118
  • 222
  • thanks for the answer but it didin't solve the problem I have a new erreur. crt0_c.c:-1: erreur : undefined reference to `WinMain@16' collect2.exe:-1: erreur : error: ld returned 1 exit status – Phenixo Dec 28 '14 at 14:29
  • Did you pass these: `-lmingw32 -lSDLmain -lSDL`? See [here](http://www.cplusplusdevelop.com/4623_17064960/). – legends2k Dec 28 '14 at 14:59
  • where should I paste it in my *.pro file ?? – Phenixo Dec 28 '14 at 15:13
  • I have add LIBS += -L C:/Qt/Tools/SDL/SDL1/lib -lmingw32 -lSDLmain -lSDL -mwindows the error has gone but I dont have a windows SDL I have only a Console when runing – I have update the question please take a look – Phenixo Dec 28 '14 at 15:39
  • These are linker flags and not libs, you've to use `QMAKE_LFLAGS`. See [here](http://doc.qt.io/qt-5/qmake-variable-reference.html). Please try to read your toolkit's documentation instead of asking everything. FYI: I've never used QMake, but I search to get the required data. You should do it too, to become independant. – legends2k Dec 28 '14 at 16:09
  • Thanks a lot. It’s my first time using a extern library with c++ and I don't know what QMAKE_LFLAGS mean and I don't have the vocabulary to read the document I tried but I have failed may be with same answers I will get the experience. It’s better to learn with question than learning with documents. Thanks again. (Note: I ‘didn’t solve the problem yet but I hope that the document will help me. I will read it now) – Phenixo Dec 28 '14 at 16:39
  • I have add this in my *.pro file and it is the same probleme a console run and no SDL window. QMAKE_LFLAGS += -mwindows -lmingw32 -lSDLmain -lSDL – Phenixo Dec 28 '14 at 16:54
  • no solution seems to work with sdl1 but I have run a window with SDL2 I don't know the difference and why it didn't run with sdl1. but I Know that your answers helped me a lot with the configration of SDL2. Can you help me find solution for the SDL1?? – Phenixo Dec 28 '14 at 21:30
  • I've never worked on SDL or Qt or QMake, so I don't know how about the specific errors you're facing. However, [here](http://blog.debao.me/2013/07/link-confilict-between-sdl-and-qt-under-windows/)'s a site where it is detailed about setting up SDL 1 with QMake. Once again, I found it through internet searching for information. Reading documentation is part of being an engineer in any field. See [this article](http://catb.org/~esr/faqs/smart-questions.html#before) on why it is so - if you think asking question is the better way. – legends2k Dec 29 '14 at 00:08
  • I had seen this document and it didn't work for me. Despite what you think, I have search a long time and I had tried many solution – Phenixo Dec 29 '14 at 01:49
0

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.

Phenixo
  • 31
  • 4