├── .gitignore ├── Qt SDL.pri ├── Qt SDL.sln ├── Qt SDL ├── MainWindow.cpp ├── MainWindow.h ├── MdiWindow.cpp ├── MdiWindow.h ├── Program.cpp ├── Qt SDL.pro ├── Qt SDL.vcxproj ├── Qt SDL.vcxproj.filters ├── SDLChild.cpp └── SDLChild.h └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # MSTest test Results 33 | [Tt]est[Rr]esult*/ 34 | [Bb]uild[Ll]og.* 35 | 36 | # NUNIT 37 | *.VisualState.xml 38 | TestResult.xml 39 | 40 | # Build Results of an ATL Project 41 | [Dd]ebugPS/ 42 | [Rr]eleasePS/ 43 | dlldata.c 44 | 45 | # Benchmark Results 46 | BenchmarkDotNet.Artifacts/ 47 | 48 | # .NET Core 49 | project.lock.json 50 | project.fragment.lock.json 51 | artifacts/ 52 | **/Properties/launchSettings.json 53 | 54 | *_i.c 55 | *_p.c 56 | *_i.h 57 | *.ilk 58 | *.meta 59 | *.obj 60 | *.pch 61 | *.pdb 62 | *.pgc 63 | *.pgd 64 | *.rsp 65 | *.sbr 66 | *.tlb 67 | *.tli 68 | *.tlh 69 | *.tmp 70 | *.tmp_proj 71 | *.log 72 | *.vspscc 73 | *.vssscc 74 | .builds 75 | *.pidb 76 | *.svclog 77 | *.scc 78 | 79 | # Chutzpah Test files 80 | _Chutzpah* 81 | 82 | # Visual C++ cache files 83 | ipch/ 84 | *.aps 85 | *.ncb 86 | *.opendb 87 | *.opensdf 88 | *.sdf 89 | *.cachefile 90 | *.VC.db 91 | *.VC.VC.opendb 92 | 93 | # Visual Studio profiler 94 | *.psess 95 | *.vsp 96 | *.vspx 97 | *.sap 98 | 99 | # TFS 2012 Local Workspace 100 | $tf/ 101 | 102 | # Guidance Automation Toolkit 103 | *.gpState 104 | 105 | # ReSharper is a .NET coding add-in 106 | _ReSharper*/ 107 | *.[Rr]e[Ss]harper 108 | *.DotSettings.user 109 | 110 | # JustCode is a .NET coding add-in 111 | .JustCode 112 | 113 | # TeamCity is a build add-in 114 | _TeamCity* 115 | 116 | # DotCover is a Code Coverage Tool 117 | *.dotCover 118 | 119 | # Visual Studio code coverage results 120 | *.coverage 121 | *.coveragexml 122 | 123 | # NCrunch 124 | _NCrunch_* 125 | .*crunch*.local.xml 126 | nCrunchTemp_* 127 | 128 | # MightyMoose 129 | *.mm.* 130 | AutoTest.Net/ 131 | 132 | # Web workbench (sass) 133 | .sass-cache/ 134 | 135 | # Installshield output folder 136 | [Ee]xpress/ 137 | 138 | # DocProject is a documentation generator add-in 139 | DocProject/buildhelp/ 140 | DocProject/Help/*.HxT 141 | DocProject/Help/*.HxC 142 | DocProject/Help/*.hhc 143 | DocProject/Help/*.hhk 144 | DocProject/Help/*.hhp 145 | DocProject/Help/Html2 146 | DocProject/Help/html 147 | 148 | # Click-Once directory 149 | publish/ 150 | 151 | # Publish Web Output 152 | *.[Pp]ublish.xml 153 | *.azurePubxml 154 | # Note: Comment the next line if you want to checkin your web deploy settings, 155 | # but database connection strings (with potential passwords) will be unencrypted 156 | *.pubxml 157 | *.publishproj 158 | 159 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 160 | # checkin your Azure Web App publish settings, but sensitive information contained 161 | # in these scripts will be unencrypted 162 | PublishScripts/ 163 | 164 | # NuGet Packages 165 | *.nupkg 166 | # The packages folder can be ignored because of Package Restore 167 | **/packages/* 168 | # except build/, which is used as an MSBuild target. 169 | !**/packages/build/ 170 | # Uncomment if necessary however generally it will be regenerated when needed 171 | #!**/packages/repositories.config 172 | # NuGet v3's project.json files produces more ignorable files 173 | *.nuget.props 174 | *.nuget.targets 175 | 176 | # Microsoft Azure Build Output 177 | csx/ 178 | *.build.csdef 179 | 180 | # Microsoft Azure Emulator 181 | ecf/ 182 | rcf/ 183 | 184 | # Windows Store app package directories and files 185 | AppPackages/ 186 | BundleArtifacts/ 187 | Package.StoreAssociation.xml 188 | _pkginfo.txt 189 | *.appx 190 | 191 | # Visual Studio cache files 192 | # files ending in .cache can be ignored 193 | *.[Cc]ache 194 | # but keep track of directories ending in .cache 195 | !*.[Cc]ache/ 196 | 197 | # Others 198 | ClientBin/ 199 | ~$* 200 | *~ 201 | *.dbmdl 202 | *.dbproj.schemaview 203 | *.jfm 204 | *.pfx 205 | *.publishsettings 206 | orleans.codegen.cs 207 | 208 | # Since there are multiple workflows, uncomment next line to ignore bower_components 209 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 210 | #bower_components/ 211 | 212 | # RIA/Silverlight projects 213 | Generated_Code/ 214 | 215 | # Backup & report files from converting an old project file 216 | # to a newer Visual Studio version. Backup files are not needed, 217 | # because we have git ;-) 218 | _UpgradeReport_Files/ 219 | Backup*/ 220 | UpgradeLog*.XML 221 | UpgradeLog*.htm 222 | 223 | # SQL Server files 224 | *.mdf 225 | *.ldf 226 | *.ndf 227 | 228 | # Business Intelligence projects 229 | *.rdl.data 230 | *.bim.layout 231 | *.bim_*.settings 232 | 233 | # Microsoft Fakes 234 | FakesAssemblies/ 235 | 236 | # GhostDoc plugin setting file 237 | *.GhostDoc.xml 238 | 239 | # Node.js Tools for Visual Studio 240 | .ntvs_analysis.dat 241 | node_modules/ 242 | 243 | # Typescript v1 declaration files 244 | typings/ 245 | 246 | # Visual Studio 6 build log 247 | *.plg 248 | 249 | # Visual Studio 6 workspace options file 250 | *.opt 251 | 252 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 253 | *.vbw 254 | 255 | # Visual Studio LightSwitch build output 256 | **/*.HTMLClient/GeneratedArtifacts 257 | **/*.DesktopClient/GeneratedArtifacts 258 | **/*.DesktopClient/ModelManifest.xml 259 | **/*.Server/GeneratedArtifacts 260 | **/*.Server/ModelManifest.xml 261 | _Pvt_Extensions 262 | 263 | # Paket dependency manager 264 | .paket/paket.exe 265 | paket-files/ 266 | 267 | # FAKE - F# Make 268 | .fake/ 269 | 270 | # JetBrains Rider 271 | .idea/ 272 | *.sln.iml 273 | 274 | # CodeRush 275 | .cr/ 276 | 277 | # Python Tools for Visual Studio (PTVS) 278 | __pycache__/ 279 | *.pyc 280 | 281 | # Cake - Uncomment if you are using it 282 | # tools/** 283 | # !tools/packages.config 284 | 285 | # Tabs Studio 286 | *.tss 287 | 288 | # Telerik's JustMock configuration file 289 | *.jmconfig 290 | 291 | # BizTalk build output 292 | *.btp.cs 293 | *.btm.cs 294 | *.odx.cs 295 | *.xsd.cs 296 | 297 | # Prerequisites 298 | *.d 299 | 300 | # Compiled Object files 301 | *.slo 302 | *.lo 303 | *.o 304 | *.obj 305 | 306 | # Precompiled Headers 307 | *.gch 308 | *.pch 309 | 310 | # Compiled Dynamic libraries 311 | *.so 312 | *.dylib 313 | *.dll 314 | 315 | # Fortran module files 316 | *.mod 317 | *.smod 318 | 319 | # Compiled Static libraries 320 | *.lai 321 | *.la 322 | *.a 323 | *.lib 324 | 325 | # Executables 326 | *.exe 327 | *.out 328 | *.app -------------------------------------------------------------------------------- /Qt SDL.pri: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------- 2 | # This file is generated by the Qt Visual Studio Tools. 3 | # ------------------------------------------------------ 4 | 5 | # This is a reminder that you are using a generated .pro file. 6 | # Remove it when you are finished editing this file. 7 | message("You are running qmake on a generated .pro file. This may not work!") 8 | 9 | 10 | HEADERS += ./Qt SDL/MainWindow.h \ 11 | ./Qt SDL/MdiWindow.h \ 12 | ./Qt SDL/SDLChild.h 13 | SOURCES += ./Qt SDL/MainWindow.cpp \ 14 | ./Qt SDL/MdiWindow.cpp \ 15 | ./Qt SDL/Program.cpp \ 16 | ./Qt SDL/SDLChild.cpp 17 | -------------------------------------------------------------------------------- /Qt SDL.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26430.16 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Qt SDL", "Qt SDL\Qt SDL.vcxproj", "{B12702AD-ABFB-343A-A199-8E24837244A3}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Release|x64 = Release|x64 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {B12702AD-ABFB-343A-A199-8E24837244A3}.Debug|x64.ActiveCfg = Debug|x64 15 | {B12702AD-ABFB-343A-A199-8E24837244A3}.Debug|x64.Build.0 = Debug|x64 16 | {B12702AD-ABFB-343A-A199-8E24837244A3}.Release|x64.ActiveCfg = Release|x64 17 | {B12702AD-ABFB-343A-A199-8E24837244A3}.Release|x64.Build.0 = Release|x64 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /Qt SDL/MainWindow.cpp: -------------------------------------------------------------------------------- 1 | #include "MainWindow.h" 2 | 3 | MainWindow::MainWindow() : MainWindowWidget(new QWidget) { 4 | setWindowTitle("QMainWindow SDL Rendering Example"); 5 | setCentralWidget(MainWindowWidget); // Basic setup, ensuring that the window has a widget 6 | setBaseSize(640, 480); // inside of it that we can render to 7 | resize(640, 480); 8 | 9 | /* 10 | I used a timer for animation rendering. 11 | I tried using update() and repaint() as the slot, but this had 12 | no effect. I later tried calling update/repaint from within the 13 | Render() slot, and this caused a flicker. The only thing that I 14 | can assume is that after the paintEvent override, qt paints the 15 | grey backgrounds. 16 | */ 17 | Time = new QTimer(this); 18 | connect(Time, SIGNAL(timeout()), this, SLOT(Render())); 19 | Time->start(1000 / 60); 20 | 21 | RendererRef = 0; 22 | WindowRef = 0; 23 | position = 0; 24 | dir = 1; 25 | } 26 | 27 | MainWindow::~MainWindow() { 28 | SDL_DestroyRenderer(RendererRef); // Basic SDL garbage collection 29 | SDL_DestroyWindow(WindowRef); 30 | 31 | delete Time; 32 | 33 | RendererRef = 0; 34 | WindowRef = 0; 35 | Time = 0; 36 | } 37 | 38 | void MainWindow::SDLInit() { 39 | /* 40 | In order to do rendering, I need to save the window and renderer contexts 41 | of this window. 42 | I use SDL_CreateWindowFrom and pass it the winId() of the widget I wish to 43 | render to. In this case, I want to render to the main central widget. 44 | */ 45 | SetWindow(SDL_CreateWindowFrom((void *)centralWidget()->winId())); 46 | SetRenderer(SDL_CreateRenderer(GetWindow(), -1, SDL_RENDERER_ACCELERATED)); 47 | } 48 | 49 | void MainWindow::Render() { 50 | // Basic square bouncing animation 51 | SDL_Rect spos; 52 | spos.h = 100; 53 | spos.w = 100; 54 | spos.y = height() / 2 - 50; 55 | spos.x = position; 56 | 57 | SDL_SetRenderDrawColor(RendererRef, 0, 0, 0, 255); 58 | SDL_RenderFillRect(RendererRef, 0); 59 | SDL_SetRenderDrawColor(RendererRef, 0xFF, 0x0, 0x0, 0xFF); 60 | SDL_RenderFillRect(RendererRef, &spos); 61 | SDL_RenderPresent(RendererRef); 62 | 63 | if (position >= width() - 100) 64 | dir = 0; 65 | else if (position <= 0) 66 | dir = 1; 67 | 68 | if (dir) 69 | position += 5; 70 | else 71 | position -= 5; 72 | } 73 | 74 | void MainWindow::SetWindow(SDL_Window * ref) { 75 | WindowRef = ref; 76 | } 77 | 78 | void MainWindow::SetRenderer(SDL_Renderer * ref) { 79 | RendererRef = ref; 80 | } 81 | 82 | SDL_Window * MainWindow::GetWindow() { 83 | return WindowRef; 84 | } 85 | 86 | SDL_Renderer * MainWindow::GetRenderer() { 87 | return RendererRef; 88 | } -------------------------------------------------------------------------------- /Qt SDL/MainWindow.h: -------------------------------------------------------------------------------- 1 | #ifndef _MAIN_WINDOW_H 2 | #define _MAIN_WINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | /* 10 | This is an old example of setting up the SDL rendering context to be the MainWindow 11 | itself. Simply replace the MdiWindow reference in Program.cpp with MainWindow. 12 | */ 13 | class MainWindow : public QMainWindow { 14 | Q_OBJECT 15 | public: 16 | MainWindow(); 17 | ~MainWindow(); 18 | 19 | void SDLInit(); 20 | void SetWindow(SDL_Window * ref); 21 | void SetRenderer(SDL_Renderer * ref); 22 | SDL_Window * GetWindow(); 23 | SDL_Renderer * GetRenderer(); 24 | private: 25 | QWidget * MainWindowWidget; 26 | SDL_Window * WindowRef; 27 | SDL_Renderer * RendererRef; 28 | QTimer * Time; 29 | int position; 30 | int dir; 31 | private slots: 32 | void Render(); 33 | }; 34 | 35 | #endif -------------------------------------------------------------------------------- /Qt SDL/MdiWindow.cpp: -------------------------------------------------------------------------------- 1 | #include "MdiWindow.h" 2 | 3 | MdiWindow::MdiWindow() : MdiArea(new QMdiArea) { 4 | MdiArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); // Show scroll bars as necessary 5 | MdiArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); 6 | 7 | setCentralWidget(MdiArea); // QMainWindow basics 8 | setWindowTitle("QMainWindow with MdiArea SDL Rendering Example"); 9 | setBaseSize(640, 480); 10 | 11 | QMdiSubWindow * MdiChild = new QMdiSubWindow(this); // Creating a basic QMdiSubWindow to show a standard 12 | MdiChild->setWindowTitle("MDI Child"); // Mdi window open along side of an SDL Mdi window 13 | MdiChild->resize(200, 200); 14 | MdiArea->addSubWindow(MdiChild); 15 | 16 | SDLChild * SdlChild = new SDLChild(this); // Creating the SDL Window and initializing it. The window 17 | SdlChild->SDLInit(); // itself must contain an inner widget, or else SDL will draw over 18 | SdlChild->setWindowTitle("MDI SDL Child"); // the window controls. Not the end of the world, but in this 19 | SdlChild->resize(200, 200); // case, its not the desired result. We must also run the SDL 20 | MdiArea->addSubWindow(SdlChild); // CreateWindow and CreateRenderer after the constructor. 21 | 22 | MdiChild->show(); 23 | SdlChild->show(); 24 | } -------------------------------------------------------------------------------- /Qt SDL/MdiWindow.h: -------------------------------------------------------------------------------- 1 | #ifndef _MDI_WINDOW_H 2 | #define _MDI_WINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "SDLChild.h" 9 | 10 | /* 11 | This is a VERY simple example of a QMainWindow set up to contain 12 | an Mdi Area. We want to show a QT window existing along side an 13 | SDL window. 14 | */ 15 | 16 | class MdiWindow : public QMainWindow { 17 | Q_OBJECT 18 | public: 19 | MdiWindow(); 20 | private: 21 | QMdiArea * MdiArea; 22 | }; 23 | 24 | #endif -------------------------------------------------------------------------------- /Qt SDL/Program.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "MdiWindow.h" 5 | #include "MainWindow.h" 6 | 7 | int main(int argc, char * argv[]) { 8 | QApplication a(argc, argv); // Basics of QT, start an application 9 | 10 | SDL_Init(SDL_INIT_VIDEO); // Basics of SDL, init what you need to use 11 | 12 | 13 | MdiWindow MdiExample; // Creating and using a QMainWindow with an Mdi Area 14 | MdiExample.show(); 15 | 16 | MainWindow MainWinExample; // Creating an using a QMainWindow with central SDL widget 17 | MainWinExample.SDLInit(); // <- Need to run SDL setup after qt window setup 18 | MainWinExample.show(); 19 | 20 | int RetVal = a.exec(); // Most examples have this on the return, we 21 | // need to have it return to a variable cause: 22 | 23 | SDL_Quit(); // We can't put this statement before the exec, or after 24 | // the return 25 | 26 | return RetVal; 27 | } -------------------------------------------------------------------------------- /Qt SDL/Qt SDL.pro: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------- 2 | # This file is generated by the Qt Visual Studio Tools. 3 | # ------------------------------------------------------ 4 | 5 | TEMPLATE = app 6 | TARGET = Qt SDL 7 | DESTDIR = ../x64/Debug 8 | QT += core uitools widgets gui 9 | CONFIG += debug 10 | DEFINES += WIN64 QT_DLL QT_UITOOLS_LIB QT_WIDGETS_LIB 11 | INCLUDEPATH += ./GeneratedFiles \ 12 | . \ 13 | ./GeneratedFiles/Debug 14 | LIBS += -lSDL2main \ 15 | -lSDL2 \ 16 | -lSDL2_image \ 17 | -lSDL2_ttf \ 18 | -lSDL2_mixer 19 | DEPENDPATH += . 20 | MOC_DIR += ./GeneratedFiles/debug 21 | OBJECTS_DIR += debug 22 | UI_DIR += ./GeneratedFiles 23 | RCC_DIR += ./GeneratedFiles 24 | include(../Qt SDL.pri) 25 | -------------------------------------------------------------------------------- /Qt SDL/Qt SDL.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | x64 7 | 8 | 9 | Release 10 | x64 11 | 12 | 13 | 14 | 15 | true 16 | 17 | 18 | true 19 | 20 | 21 | true 22 | 23 | 24 | true 25 | 26 | 27 | true 28 | 29 | 30 | true 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | $(QTDIR)\bin\moc.exe;%(FullPath) 40 | Moc%27ing MainWindow.h... 41 | .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp 42 | "$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DUNICODE -DWIN32 -DWIN64 -DQT_CORE_LIB -DQT_GUI_LIB -DQT_UITOOLS_LIB -DQT_WIDGETS_LIB "-I.\GeneratedFiles" "-I." "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtUiTools" "-I$(QTDIR)\include\QtWidgets" 43 | $(QTDIR)\bin\moc.exe;%(FullPath) 44 | Moc%27ing MainWindow.h... 45 | .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp 46 | "$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DUNICODE -DWIN32 -DWIN64 -DQT_NO_DEBUG -DNDEBUG -DQT_CORE_LIB -DQT_GUI_LIB -DQT_UITOOLS_LIB -DQT_WIDGETS_LIB "-I.\GeneratedFiles" "-I." "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtUiTools" "-I$(QTDIR)\include\QtWidgets" 47 | 48 | 49 | 50 | 51 | $(QTDIR)\bin\moc.exe;%(FullPath) 52 | Moc%27ing MdiWindow.h... 53 | .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp 54 | "$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DUNICODE -DWIN32 -DWIN64 -DQT_CORE_LIB -DQT_GUI_LIB -DQT_UITOOLS_LIB -DQT_WIDGETS_LIB "-I.\GeneratedFiles" "-I." "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtUiTools" "-I$(QTDIR)\include\QtWidgets" 55 | $(QTDIR)\bin\moc.exe;%(FullPath) 56 | Moc%27ing MdiWindow.h... 57 | .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp 58 | "$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DUNICODE -DWIN32 -DWIN64 -DQT_NO_DEBUG -DNDEBUG -DQT_CORE_LIB -DQT_GUI_LIB -DQT_UITOOLS_LIB -DQT_WIDGETS_LIB "-I.\GeneratedFiles" "-I." "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtUiTools" "-I$(QTDIR)\include\QtWidgets" 59 | 60 | 61 | $(QTDIR)\bin\moc.exe;%(FullPath) 62 | Moc%27ing SDLChild.h... 63 | .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp 64 | "$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DUNICODE -DWIN32 -DWIN64 -DQT_CORE_LIB -DQT_GUI_LIB -DQT_UITOOLS_LIB -DQT_WIDGETS_LIB "-I.\GeneratedFiles" "-I." "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtUiTools" "-I$(QTDIR)\include\QtWidgets" 65 | $(QTDIR)\bin\moc.exe;%(FullPath) 66 | Moc%27ing SDLChild.h... 67 | .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp 68 | "$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DUNICODE -DWIN32 -DWIN64 -DQT_NO_DEBUG -DNDEBUG -DQT_CORE_LIB -DQT_GUI_LIB -DQT_UITOOLS_LIB -DQT_WIDGETS_LIB "-I.\GeneratedFiles" "-I." "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtUiTools" "-I$(QTDIR)\include\QtWidgets" 69 | 70 | 71 | 72 | {B12702AD-ABFB-343A-A199-8E24837244A3} 73 | Qt4VSv1.0 74 | 10.0.16299.0 75 | 76 | 77 | 78 | Application 79 | v141 80 | 81 | 82 | Application 83 | v141 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | $(SolutionDir)$(Platform)\$(Configuration)\ 92 | C:\Frameworks\SDL\include;$(IncludePath) 93 | C:\Frameworks\SDL\lib\x64;$(LibraryPath) 94 | 95 | 96 | $(SolutionDir)$(Platform)\$(Configuration)\ 97 | 98 | 99 | 100 | UNICODE;WIN32;WIN64;QT_CORE_LIB;QT_GUI_LIB;QT_UITOOLS_LIB;QT_WIDGETS_LIB;%(PreprocessorDefinitions) 101 | .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtUiTools;$(QTDIR)\include\QtWidgets;%(AdditionalIncludeDirectories) 102 | Disabled 103 | ProgramDatabase 104 | MultiThreaded 105 | true 106 | 107 | 108 | Windows 109 | $(OutDir)\$(ProjectName).exe 110 | $(QTDIR)\lib;%(AdditionalLibraryDirectories) 111 | true 112 | Qt5Core.lib;Qt5Gui.lib;Qt5UiTools.lib;Qt5Widgets.lib;SDL2main.lib;SDL2.lib;SDL2_image.lib;SDL2_ttf.lib;SDL2_mixer.lib;%(AdditionalDependencies) 113 | 114 | 115 | xcopy /d /y "C:\Frameworks\SDL\lib\x64\SDL2.dll" "$(OutDir)" 116 | xcopy /d /y "C:\Frameworks\Qt\5.9.2\msvc2017_64\bin\Qt5Widgets.dll" "$(OutDir)" 117 | xcopy /d /y "C:\Frameworks\Qt\5.9.2\msvc2017_64\bin\Qt5Gui.dll" "$(OutDir)" 118 | xcopy /d /y "C:\Frameworks\Qt\5.9.2\msvc2017_64\bin\Qt5Core.dll" "$(OutDir)" 119 | 120 | 121 | 122 | 123 | UNICODE;WIN32;WIN64;QT_NO_DEBUG;NDEBUG;QT_CORE_LIB;QT_GUI_LIB;QT_UITOOLS_LIB;QT_WIDGETS_LIB;%(PreprocessorDefinitions) 124 | .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtUiTools;$(QTDIR)\include\QtWidgets;%(AdditionalIncludeDirectories) 125 | 126 | MultiThreadedDLL 127 | true 128 | 129 | 130 | Windows 131 | $(OutDir)\$(ProjectName).exe 132 | $(QTDIR)\lib;%(AdditionalLibraryDirectories) 133 | false 134 | qtmain.lib;Qt5Core.lib;Qt5Gui.lib;Qt5UiTools.lib;Qt5Widgets.lib;%(AdditionalDependencies) 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | -------------------------------------------------------------------------------- /Qt SDL/Qt SDL.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {D9D6E242-F8AF-46E4-B9FD-80ECBC20BA3E} 14 | qrc;* 15 | false 16 | 17 | 18 | {99349809-55BA-4b9d-BF79-8FDBB0286EB3} 19 | ui 20 | 21 | 22 | {D9D6E242-F8AF-46E4-B9FD-80ECBC20BA3E} 23 | qrc;* 24 | false 25 | 26 | 27 | {71ED8ED8-ACB9-4CE9-BBE1-E00B30144E11} 28 | moc;h;cpp 29 | False 30 | 31 | 32 | 33 | 34 | Source Files 35 | 36 | 37 | Generated Files 38 | 39 | 40 | Generated Files 41 | 42 | 43 | Source Files 44 | 45 | 46 | Generated Files 47 | 48 | 49 | Generated Files 50 | 51 | 52 | Source Files 53 | 54 | 55 | Generated Files 56 | 57 | 58 | Generated Files 59 | 60 | 61 | Source Files 62 | 63 | 64 | 65 | 66 | Header Files 67 | 68 | 69 | Header Files 70 | 71 | 72 | Header Files 73 | 74 | 75 | -------------------------------------------------------------------------------- /Qt SDL/SDLChild.cpp: -------------------------------------------------------------------------------- 1 | #include "SDLChild.h" 2 | 3 | SDLChild::SDLChild(QWidget * parent) : QMdiSubWindow(parent) { 4 | /* 5 | If you do not set an inner widget, the SubWindow itself IS 6 | a widget, so SDL renders over it... AND its controls. Not 7 | quite the desired behavior, unless you want to hide the 8 | controls until mouse over. But once the mouse is over, SDL 9 | writes over the controls again. Keep this in mind. 10 | */ 11 | setWidget(new QWidget); 12 | 13 | /* 14 | I used a timer for animation rendering. 15 | I tried using update() and repaint() as the slot, but this had 16 | no effect. I later tried calling update/repaint from within the 17 | Render() slot, and this caused a flicker. The only thing that I 18 | can assume is that after the paintEvent override, qt paints the 19 | grey backgrounds. 20 | */ 21 | Time = new QTimer(this); 22 | connect(Time, SIGNAL(timeout()), this, SLOT(Render())); 23 | Time->start(1000 / 60); 24 | 25 | RendererRef = 0; 26 | WindowRef = 0; 27 | position = 0; 28 | dir = 1; 29 | } 30 | 31 | SDLChild::~SDLChild() { 32 | SDL_DestroyRenderer(RendererRef); // Basic SDL garbage collection 33 | SDL_DestroyWindow(WindowRef); 34 | 35 | delete Time; 36 | 37 | RendererRef = 0; 38 | WindowRef = 0; 39 | Time = 0; 40 | } 41 | 42 | void SDLChild::SDLInit() { 43 | /* 44 | In order to do rendering, I need to save the window and renderer contexts 45 | of this window. 46 | I use SDL_CreateWindowFrom and pass it the winId() of the widget I wish to 47 | render to. In this case, I want to render to a widget that I added. 48 | */ 49 | SetWindow(SDL_CreateWindowFrom((void *)widget()->winId())); 50 | SetRenderer(SDL_CreateRenderer(GetWindow(), -1, SDL_RENDERER_ACCELERATED)); 51 | } 52 | 53 | void SDLChild::Render() { 54 | // Basic square bouncing animation 55 | SDL_Rect spos; 56 | spos.h = 100; 57 | spos.w = 100; 58 | spos.y = height() / 2 - 50; 59 | spos.x = position; 60 | 61 | SDL_SetRenderDrawColor(RendererRef, 0, 0, 0, 255); 62 | SDL_RenderFillRect(RendererRef, 0); 63 | SDL_SetRenderDrawColor(RendererRef, 0xFF, 0x0, 0x0, 0xFF); 64 | SDL_RenderFillRect(RendererRef, &spos); 65 | SDL_RenderPresent(RendererRef); 66 | 67 | if (position >= width() - 100) 68 | dir = 0; 69 | else if (position <= 0) 70 | dir = 1; 71 | 72 | if (dir) 73 | position += 5; 74 | else 75 | position -= 5; 76 | } 77 | 78 | void SDLChild::SetWindow(SDL_Window * ref) { 79 | WindowRef = ref; 80 | } 81 | 82 | void SDLChild::SetRenderer(SDL_Renderer * ref) { 83 | RendererRef = ref; 84 | } 85 | 86 | SDL_Window * SDLChild::GetWindow() { 87 | return WindowRef; 88 | } 89 | 90 | SDL_Renderer * SDLChild::GetRenderer() { 91 | return RendererRef; 92 | } -------------------------------------------------------------------------------- /Qt SDL/SDLChild.h: -------------------------------------------------------------------------------- 1 | #ifndef _SDL_CHILD_H 2 | #define _SDL_CHILD_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | class SDLChild : public QMdiSubWindow { 11 | Q_OBJECT 12 | public: 13 | SDLChild(QWidget * parent); 14 | ~SDLChild(); 15 | 16 | void SDLInit(); 17 | void SetWindow(SDL_Window * ref); 18 | void SetRenderer(SDL_Renderer * ref); 19 | SDL_Window * GetWindow(); 20 | SDL_Renderer * GetRenderer(); 21 | private: 22 | QWidget * MainWindowWidget; 23 | SDL_Window * WindowRef; 24 | SDL_Renderer * RendererRef; 25 | QTimer * Time; 26 | int position; 27 | int dir; 28 | private slots: 29 | void Render(); 30 | }; 31 | 32 | #endif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | I have been trying for a while now to marry Qt and SDL together. Specifically, to use Qt for the GUI/Window Management System, and to have SDL render on to a window/widget. I finally accomplished this with the application rendering 2 SDL windows at 60 fps. 2 | 3 | In order to edit the program, you will need Qt 5.9 and SDL 2.0.4. Other minor versions may work, but these are the versions I wrote the example with. You will also need to install a VSIX from Qt to be to compile in Visual Studio. This is required to auto generate the MOC files that qmake requires. Otherwise I have included the Qt project file. I do not know if it includes my library and include settings, or my library xcopy Post-Build events. 4 | 5 | Upon running the application, 2 windows will appear. The first is a standard QMainWindow example with SDL rendering to the centralWidget position. The second is a QMainWindow with the QMdiArea set. I then proceed to open two QMdiSubWindow's, the first is a standard window, the second is the SDL rendered window. --------------------------------------------------------------------------------