 Hey everybody, it's Brian and welcome to the 111th Qt tutorial with C++ and GUI programming. We are continuing our series on zip files and Qt. If you're just tuning in, go ahead and watch video 110 where I kind of explained, you know, the zip file format a little bit and some of the research that I've done, this really awesome blog I found, some little gotchas about using Qt with zip, and the libraries we're going to be using. Q UA zip, is it Q UA zip or QA zip? I don't know, I keep going back and forth. And the trustee is Zlib. Alright, so today what we're going to be doing is actually building Zlib and building Q UA zip or QA zip. Somebody tell me how you actually pronounce that. Some of these names are kind of cool, but so before we really begin, somebody's probably going to ask, why are you using Zlib? Why are you using Q UA zip? Well, we're using Zlib because it's free, it's open source, and it's one of the better libraries out there. A lot of programs actually use this under the hood, they just don't tell you. We're using Q UA zip or QA zip because it's a wrapper around Zlib. Now when I say a wrapper, what does that mean? It means somebody went out, I shouldn't say somebody, this gentleman went out, and he wrote the code to actually wrap around that Zlib library so you don't have to interact with pointers or screw around with C code or any of that nonsense. You just deal with Q to objects. Simple, easy to use. Alright, well if it was that easy, these tutorials wouldn't exist. That being said, let's get right to the heart of the matter here. Alright, if you've been following along, you should have a directory structure similar to this where you have a Libs folder, an original folder which just contains files we're going to compress in future tutorials, and three or actually two zip files I should say. You're going to have the Q UA zip source and the Zlib source. Now remember, if you're on Windows, you can download the pre-compiled DLL. He made your life a little easier. If you're not on Windows, we're going to have to do some like little extra legwork. Man, cannot talk today. And this is the actual source code for Zlib. So all we're going to do is we're just going to extract. And I'm going to extract. Let's see, where is it? This guy. So now you should have four folders. Two of which, one is the QA zip and one is Zlib. The first thing we need to do, if you're on not Windows, aka Mac, Unix, Linux, BSD, one of those derivatives, we need to actually build Zlib. Now if you're on Windows, your life's a little easier. You can just go in and take Zlib 1 DLL, put it in this lib folder, take Zlib DLL dot lib and Zlib dot def and also put those in the lib folder. Go back, take the include files, Zlib H and Z config and throw those in Q UA zip, which we're going to do also for Linux. So just follow along. All right. So we're going to copy this. We're going to bring open the trustee command prompt here. And if you're following along, this is only if you are not on Windows. You will need to compile Zlib yourself. If you're on Windows and you just feel like doing it, you can go ahead and give it a shot. We're going to change directory into the Zlib directory. Going to configure. Now if you see anything other than this, like if you see access denied or something like that, make sure that config file is actually writable. I should say this guy right here, not writable. Sorry executable. If it's not executable, you're going to get an error message. All right. Now that we've configured it, we just simply type make and it'll start grinding away doing its thing. All right, it's done. Now, if you do not get to this point, if you get some horrendous error and it just crashes and burns, well, you're going to need to figure that out. I'm probably going to get a metric ton of email saying, hey, Zlib wouldn't compile, blah, blah, blah. Unfortunately, I can't really help you out with that. It's going to be something specific to your operating system. Maybe you've got a file you don't have access to or a crop file you need to redownload the zip, but it's really simple. You just do configure and then you do make and it builds it. Once it's built, you can sort by type and you see all these lovely objects out here. Now, take Zlib, or I'm sorry, libz.a and then grab these SO files. Copy those. Put them in your lib folder like I've done here. See, you just paste and we're just going to replace, replace, and replace. So what are these? Well, a .so is very similar to a DLL in Windows. A .so.1 I think is very similar to a definition file and a .a, that's what you're actually going to be linking to. Now, if you're going to be doing the Windows version, let's actually just extract this here. There's our DLL. The DLL's already compiled, so we're going to grab that, throw that in here. I'm going to actually make a subfolder called Windows. So there's your DLL. And then you're going to need the library files, these guys. Whoops. So you will have Zlib, I'm sorry, Zdll.lib, Clib.def, and Zlib1.dll. That's for your Windows. If you're in Linux, you're going to have these guys. The libz.a, libz.so, libz.so.1. I shouldn't say if you're in Linux, even if you're in not Windows. This includes Mac, Unix, blah, blah, blah. All right. Now that we've got all that, let me do some little housekeeping here. What we're going to do is actually open up QUA-zip and play around with that. We're going to compile that. So let's go File. Actually, I've already got it in here. Configure Project. Now I'm only opening QUA-zip, meaning if you go in here, you're going to see there is a project file here, which is just quite simply a template sub-durs, meaning it just has directories in there. And it's quite literally just opening up these two directories. The QZ test has a bunch of test functionalities in there. I should say test functions. I did not get these to work out of the box. They did not compile. There's an incompatibility between the version he wrote for Qt and the version I'm writing for Qt. I suspect he did 4.7. I'm doing 5.2. Yeah, I could not get them to work. So, without further ado, you just open this up. Here's the actual source, but we're going to look at it in Q. One thing you need to do, let's back out here. Let's go into Zlib. And you need to grab Zlib.h and Zconf.c. You need to do that for any operating system you're on. You need to copy these into the QAZip folder. That way we can actually chit chat with Zlib. You notice how they're not in the headers? So, we need to add existing files. Now they're in there. This is the header for Zlib. This is the actual C header. This is what he's interacting with. All right? And all these other headers are for QAZip. And there's the source for QAZip. And you can go in here. And if you wanted to browse around and read it and it gets quite confusing if you're not an expert in Zip files. But we want something simple, easy to use. Now, this comes with a very big disclaimer. This may compile on some operating systems as we have it right now. It may not on others. We're going to fix that. So, what we're going to do is we're going to say enter. And we're going to give it the actual path to our libraries here. We're going to say include path. Ooh, we're already spotted in there. Here we go. And then we should say unix. What we're doing here is making a conditional saying if we're on unix, do this. And I'm going to explain this here in a second. I just want to type it out. And then we're going to copy this because I'm a huge fan of copy and paste. And we're going to say Zdll. Whoops. It came up called dll today. Save that. Wait for it to do its evaluating and parsing. If you don't see this green run button, then you've done something wrong. If that's grayed out, that means it can't parse it correctly now. Let's explain what we've done here. We're saying we're making a variable here called libdir. And we're giving the path to our libraries right here. This is where if you're in Windows, you're going to have your dll and your a file and your def file on Linux, unix, et cetera. You're going to have your a and your sos. We're including that. We're adding it to the include path, telling Qt to go ahead and search that path. Then we're using that variable. That's how you use a variable. You use dollar sign, dollar sign. And then what are those called again? They're not parentheses. I forget. Anyways, you know what it is. Then we have conditional. If we're on unix, include that library. Now what we're saying here is the lib plus equals, meaning we're saying to the libraries add and then the capital L dash capital L is the path. The dash lowercase L is the actual library name. You could do the just full path, but it's easier if you do this. If we're on Windows, same deal, but we're including zdll. All right. Now if we try to compile this, this may work. It may not. We're going to tweak around with it a little bit. That's the official term. So we're going to rebuild it. And if you're so inclined, you can watch the compile output. Sometimes it's just hypnotizing to watch that and it built. If you run into a problem, I will warn you right now. Try deleting that. If you're not on Windows, if you are on Windows, you're going to need to actually link to the Zlib library right here using that code. If you're on Mac, unix, et cetera, et cetera, it may work. It may not. Just give it a good rebuild just in case. Tick tock, tick tock. All right. Two warnings. No issues. We're golden. If you get a bunch of warnings or I'm sorry, a bunch of errors, like undefined reference to blah, blah, blah. That means it can actually find the DLL. If you get a symbol redefined or some error message like that, that means try deleting this chunk right here if you're not in Windows. Because what is happening is he's actually linking directly to Qt. And we're saying no, link directly to Zlib. And sometimes there'll be a conflict there. So those are some gotchas you need to be aware of. All right. Now if we go out here and to our build directory, you should see there's our lovely. If you're on Windows, you're going to see a DLL. Libqazip. And either SO for system object or DLL if you're in Windows. That's all for this tutorial. Thank you for watching. I hope you found this educational entertaining. And stay tuned because we're going to be working with these in future tutorials.