 Hey everybody, this is Brian and welcome to the 110th Qt tutorial with C++ and GUI programming. Alright, everybody has special projects they're working on. One of mine actually includes zip files. So we are going to embark. Let me bring my notes out here. I actually do use notes when I kind of make these tutorials. Sometimes I get a little ADD. This is going to be a four part series. Video 110. We're going to introduce setup directories, download some code. Video 111. We're going to actually build some code. Video 112. We're going to actually link to Zlib using QAZip, which we'll cover here in a minute. And video 113. We will use QAZip directly in a project and link to Zlib. Now if all of that sounds like what the heck is he talking about? Don't worry, we're going to cover it. So, what is a zip file? Well, if you don't know what a zip file is, you probably shouldn't be watching these tutorials. But we're going to cover it just in case. Zip files is an archive, which takes a bunch of files, compresses them, and throws them into a single file called a Zlib archive. Now, back in the day, there was a big war over what should be the official standard. We've all kind of decided that there's this PKZip program that I don't know if it even still exists. I'm sure it's out there, but that kind of became the standard. There's other standards out there, but you'll see a lot of things that are PKZip compatible. And that's really what we're chasing here. And you can read on and on, and really if you want to see the structure for these are really complex compared to what we've been working with here. And you can go out to Google Images and actually get a little better insight. There'll be like a local header, a file, a central directory, end of central directory. That's kind of the structure of these things. And individual files can be compressed at different ratios and password protected or the entire archive can be protected. It gets really complex. So to write code from the ground up that covered all of this would take months. I mean, I could make an entire video series spanning two years doing this. But that's not what we want. We want quick and easy. I like quick and easy. I know you like quick and easy. So if you go out and you Google, you know, cute, zipping and unzipping files, you'll see a lot of answers that pop up. And a lot of things keep repeating like QAZip, Q-Compress and uncompress, and OSDAB. Well, QAZip is what we're going to be using. So I'll cover the other ones real quick. Q-Compress and uncompress are part of the official Qt API, but there's a gotcha. They only compress a single file, meaning you're not going to take an entire directory and put it into a zip archive. OSDAB, I haven't really played around with that too much. I've heard good things. It just decided not to use it. Let's see here. There is also this blog I stumbled upon, www.mimc.org. He talks about how that's actually internally included in Qt. And this got kind of confusing to me until I started reading this blog. And it's actually really well done. Did I say really welly? I did. Really well done. And what he's saying is that they've actually, they being cute, have actually created a QZip reader and QZip writer class that internally uses a library called Zlib, which is PKZip compatible, I believe. All you really have to do is include the Zlib header and add this code to your project file. Note you'll have to actually spell out where the libraries are. But there are other gotchas. For example, you'll have naming conflicts. I said, well, why would you have naming conflicts? When you go out to the actual source code, this is Qtorious, which actually holds the source code for Qt. And when you find the QZip reader and QZip writer and you just open one of these little guys up, everything looks normal until you see this. Warning. Well, that's not good. Warning. This file is not part of the Qt API. It exists for the convenience of the Qt library class. This header file may change from version to version without notice or even be removed. We mean it. That's kind of an ominous warning. What that tells you right there is if you go down that path, your source code may suddenly stop working when they release a new version of Qt or even a bug fix. That's not good. But he goes on to explain how to actually get it working if you're so inclined. I haven't played around a whole lot with this because I really don't want to go back and troubleshoot a program that's been working for a few years. I'm hoping that enough of you out there will scream to the authors of Qt and say, hey, make this part of the official API. We want to be on par with Java and .NET, where they have built-in zip handling right in the libraries. All right, so without further ado, you're going to need to go out to quazip.sourceforge.net, download this package. The download link is right here off Sourceforge. This should work with, and he says, Linux, FreeBSD, HP Unix, Windows, and some Symbians. This is essentially just a wrapper. See, it says QUazip, or quazip is a simple wrapper over the zip-on-zip package. Well, this is the zip-on-zip package, Zlib. Ta-da. Zlib is a C library. I mean, it's a library written in C. Remember, we use C++, which is kind of the grandfather of C. The reason why you use QAZip is so you don't have to interact directly with this library and deal with pointers and all that garbage. It's simple, reusable, fun, and exciting. Well, I may have exaggerated on the fun and exciting, but you know what I mean. You don't want to muck around with pointers and memory management. You just want to zip-on-zip a file. So, grab the QUazip source. That's all written in Qt, by the way. And the Zlib source. Now, I should point out, there's a gotcha here. If you're on Linux, or Unix or Mac, download this file. Zlib source code version 1.2.8. That may actually date this tutorial in the future. If you're on Windows, your job's already done. You download this. It is a compiled DLL. Let me bring up my directory here. Excuse me, I still got a frog in my throat. I'm getting over this cold. You're also going to need to create some directories here. Create a Libs directory. Create an original directory. This is going to contain files in it that we're going to want to compress. Here's your QUazip. This is the source code for the Quazip DLL. This actually compiles to a DLL. If you explore it, you'll see there's a Documents folder, the actual Library folder, and a Test folder, which has all the test source code in it. Now, if you get all excited, run out, download this, and try to compile it here, you're going to run into a lot of issues. And that's what we're going to be covering in the next tutorial, is how to actually compile that bad boy. I actually spent an afternoon banging my head against the keyboard trying to get that to work. Finally got it. Very happy. Now, with Zlib, there's the two versions. The Windows version, which actually has the DLL already compiled, and you should note the Lib folder has the includes, the Lib includes. This is what you will link against. Remember in your C++ classes, they talked about linking? Well, we're going to be doing a lot of that. And the actual include files, the headers for Zlib. If you're on not Windows, you're going to have to actually get the source code. And here's the actual Zlib source code. And we are going to be compiling that, but not in this tutorial. That's all for this tutorial. This is Brian. Thank you for watching. Please visit my website, www.voidrealms.com, where I will have the source code to this and all the other tutorials out there. If you're following along and you find a tutorial, like this guy who's missing the ZIP file, go ahead and zip that up, send it to me and I will review it and post it for the rest of the world to use. I had a server crash and I'm trying to recover from it. That's it.