 Hey everybody, this is Brian, and welcome to the, oh wow, the 84th Qt tutorial with C++ Inquiry Program. We are getting up in these things, and we'll call this myTest. Throw this in the usual location, wherever you're putting it. That's what she said. Yeah, I know, a couple of you are out there giggling. And next, next, finish, finish. And I'll be brutally honest here, we're actually not going to write a lick of code. What we're going to cover today is how to deploy your application. I've had several, actually several dozen messages saying, hey Brian, I wrote my program. I want to give it to a friend of mine. When they go to run it, they get all sorts of errors that I just don't understand. Now notice how I just built that in debug mode. Go ahead and flip this into release mode also, and run it again. And once it's done building, now what's the difference between debug and release? Well, debug is typically what you do when you're developing your application. Debug adds all sorts of symbols and little hooks into the software so that when it compiles, the debugger can go through and figure out where you are and step through that code. The resulting executable will be slightly larger, but it'll have all the debugging symbols make life a little easier. Release, that's what you give to the end user. That's what you give to your friend, your boss, your customers, whatever. Release is a more polished, clean version. It's much smaller, better compiled, more compact. Same program, just compiled differently. Now what does that mean for you out in Qtland? You've got your place wherever you're putting your code. You notice how you've got your debug and release folder. We'll go into debug. You can see this is 840 kilobytes, whereas this one is 84, much, much smaller, much more compact, more streamlined. You go to run this. Well, you get this error. What in the world? mainwm10.dll is missing from your computer. Try reinstalling. But why does it work in Qt Creator? I mean, we just ran this, but it doesn't work from your hard drive. The answer is simple. You need to have the DLLs in the correct path. Something that Qt has, but if you're going to give this to an end user, something we're going to need to set up. So the first thing you need to do is figure out what you actually need. Well, there's two methods of doing this. You can run this, get the name, go find the DLL, run it again. I guarantee you there'll be more and more and more. Or you can use this program, Dependency Walker. Dependency Walker was developed by Steve P. Miller. And it is distributed, and I think actually owned now, by the Microsoft Corporation. And what this does is you can just download this off of Google, just actually go type Dependency Walker into Google, and you'll find a direct link to it. Go ahead and select the executable you want to release. In this case, mytest.exe in the Release folder. Uh-oh. Air is detected, air opening file. What this does is it tells you exactly what this program needs to run. You see, mytest.exe needs kernel 32, which it found. That's part of the operating system. MSVCRT.DLL, Microsoft Visual C Runtime.DLL, another Microsoft Visual C Runtime.DLL. And then it needs this MingWM10.DLL. What is that? Well, with Qt, I should say with Qt Creator, we use the MingW Compiler. So it needs the Ming Runtime. If you compiled your code with Visual Studio, chances are you're just going to need the Microsoft Visual C Runtime. And then you, of course, need the QtCore4.DLL and QtGui4.DLL. What are these? Well, all those namespaces you import. Let's go back into our program here. See how you've got QtGui. And then, of course, you've got QtCore right here. QtCore and GUI. Those are the two libraries you're actually importing right there. So you need the underlying library, Core and GUI. So there's Core and GUI. Now you notice how it's QtCore4 and QtGui.DLL. When they actually upgrade this to 5, it'll probably say QtCore5 and QtGui5. So you should bear in mind the different versioning of the DLL. So that's why this program won't run. We're missing these DLLs. Remember when we tried to run it, it said missing MingWM10.DLL? Well, let's go find these things. Now if you go to your hard drive and you go to wherever you have QtCreator installed, you've got Operating System, Qt, and then you've got all these. Here is the Ming32. Now you can typically go out to the bin folder. And then you can find what you need from there. See there's that MingWM10.DLL. Now here's the tricky part about DLLs. You copy and paste this out here. Let's actually get rid of these object files and all that mock stuff. When we run this, now we've got the Ming10. Suddenly it wants QtCore4.DLL. Remember, back from depends. It has this. Now we need QtCore4.DLL. So let's go find these. And what you need to look in is your Qt installation under Qt under bin. And I know that sounds a little confusing. So let's actually step through this. You've got your Qt installation. And then there's 2010, 05, and then Qt and bin. Now I've done this couple times, so I kind of know what to look for here. You're going to want the Ming. You're going to want the libgcc. And we want the QtCore4.DLL. Now you notice how there's this Corde4.DLL right underneath that. What's the difference here? Well, Core4 is the release. And Corde4, notice the D, is for debug. So if you did this in debug mode, you'd have to release the debug DLLs, which are much, much bigger. 2.43 versus 37 megs. And then we'll grab the QtCore4. Copy these. And let's just paste them right in here. And let's just copy and replace that Ming. So now we've got our DLLs here and our EXE. And we run this. Magically it runs. So you can't just hand over the EXE. You've got to actually hand over these DLLs also. Now, these DLLs can be in the same directory as the application, or more typically, you put them in the system directory, which is like C, Windows, System32. That way, any program that uses those DLLs will be able to use those. Now, there is a trick here. And I want to show you something very important, because I know some of you out there are going to make this mistake, because I've done it a couple times myself. Let's go back out to the Ben folder here. You notice how it was Qt 2010.5? That number may actually change depending on what build you have. And then Qt and Ben. Well, if you go to Qt, there's our Ben folder. Go back up to 2005. Notice there's a Ben folder right here. If you go in here, notice there's a Qt4 right here. Let's copy that. Go out to release and let's paste this out here. Core4, actually, let's rename this right here. That way, I don't have to go hunt for it again. Now, it looks like we have all the information we need here. We have all these DLLs. But when you run this, it says the procedure entry point and then some wacky thing could not be located in the dynamic link library, qtcore4.dll. What does that mean? I mean, we got the library. It's right here. What's going on? Well, the answer is very simple. Qt was compiled with Visual Studio, a.k.a. the Microsoft Visual C++ runtime. Qt Creator was also compiled with that. But your programs are compiled with MingW, a different compiler. So you need a different set of libraries. The library that we have here was compiled with Visual Studio, this old one that actually runs was compiled with Ming. Now, how can you tell the difference? Well, that, my friends, is the trick. You've got to really know what you're looking for. Unfortunately, I'm not really qualified to tell you that. But you can kind of open them up in DependencyWalker if you really want to. So let's open this up again. And notice it'll say errors detected. And notice how it's complaining qtcore4. DependencyWalker is actually a very smart program. It knows. You see these NA, NA, these entry points. Actually, that's the one right there. It was complaining about. So it can tell you ahead of time if you're going to have problems. Now, if you're wondering what all this stuff underneath, and that's how you can expand and collapse, well, you guessed it, even these DLLs have dependencies. So qtcore4 needs to have kernel32, user32, OLE32, I mean all these other things. And yes, the Microsoft Visual C runtime, 9.0. So let's go back out here. Let's delete that because we don't need it. Rename this. And let's open up DependencyWalker again. Let's actually close that app. And notice how it didn't complain about any error messages and qtcore4 is all green now. It's because it's checking all the entry points. That's how we know this thing's going to run. Now, what that says is that your system has all the DLLs you need. Doesn't say that the end user system's going to have all the DLLs. In a perfect world, what you would do is you would take your executable and all the DLLs and package it up and give it to the end user. Now, in the real world, it's a little more complex. My recommendation to you is to go out and get yourself a good installation program, such as install shield and of course, now that I'm on the spot, I'm drawing a blank, I know there's some really good ones out there. Drop me a line on YouTube if you want to mention. But they will go out and they will scan your executable, just like DependencyWalker did. But they will grab all the DLLs, all these files, and they will package them up nice and neat for you. And then when it's installing on the end user's computer, it'll check to make sure, do they have it? Yes, no. If they do, it won't touch it. If they don't, it'll install it. So from your friend's perspective, he runs, yes, an annoying installer where he's doing, next, next, next. But then everything just magically works. And he doesn't have to really care about all this mess that is under the hood here that you have to worry about. Now, the good news is the majority of these things are already going to be on the end user's computer, like kernel 32, Microsoft Visual C runtime. Those are pretty much all on the end user system. So are like OLE32. Unfortunately, I can't list them all. But just know that the by and large of the majority of them are going to already be. Now, we needed the libgcc underscore sdw2-1. Remember, I grabbed that initially. I've done this a few times, so I know just through trial and error that you need that. And that's because it is compiled with the libgcc. All right, enough talking. Before I go, I wanted to say thank you, everybody, for your continued support. I want to dispel some rumors that, no, I am not going to stop doing cute tutorials. I'm actually very fond of cute. Actually, my goal is to get over 100 tutorials by the end of the summer. So if you've got any questions, comments, concerns, drop me a line. Just please be patient. I get just an ungodly amount of messages. I had just 200 over the last day and a half, and it's going to take me a while to sift through them. So shoot me your feedback, but please be patient if I don't answer you right away, because I'm trying to catch up with everybody. Anyways, this is Brian. Have a good one.