Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Apress committed Oct 11, 2016
0 parents commit 3a07989
Show file tree
Hide file tree
Showing 552 changed files with 32,552 additions and 0 deletions.
Binary file added 3643.pdf
Binary file not shown.
Binary file added 3645.pdf
Binary file not shown.
Binary file added 9781590598313.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 69 additions & 0 deletions Chapter01/README.txt
@@ -0,0 +1,69 @@
This file is a part of 1590598318-1.zip containing example source code for the
Foundations of Qt Development book available from APress (ISBN 1590598318).

These are the examples for chapter 1 - The Qt Way of C++

plain-cpp

Listings 1-1, 1-3

The MyClass example class in pure C++. No Makefile or QMake project is
included, build the cpp file using your C++ compiler.


cpp-with-qobject

Listings 1-2, 1-4

The MyClass example class inheriting QObject.


cpp-with-qstring

Listing 1-5

The MyClass example class now uses QString instead of std::string.


hello-world

Listings 1-6, 1-7

A simple hello world demostration to show how QMake and QMake project files
are used to build Qt applications.


signals-and-slots

Listings 1-8, 1-9

The MyClass example class now emits signals and provides slots.


gui-connection

Listings 1-10, 1-11, 1-12

The MyClass example class is used as a bridge to carry text from one widget to
another.


qlist

Listings 1-13, 1-14, 1-15, 1-16

Demonstrations of the QList class.


stringlist-stack-queue

Listings 1-17, 1-18

Demonstrations of the QStringList, QStack and QQueue classes.


map-hash-set

Listings 1-19, 1-20, 1-21, 1-22, 1-23, 1-24, 1-25, 1-26, 1-27, 1-28, 1-29

Demonstrations of the QMap, QHash, QSet, QMultiMap and QMultiHash classes.
74 changes: 74 additions & 0 deletions Chapter01/cpp-with-qobject/cpp-with-qobject.cpp
@@ -0,0 +1,74 @@
/*
* Copyright (c) 2006-2007, Johan Thelin
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of APress nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/

#include <string>
using namespace std;

#include <QtDebug>
#include <QObject>

class MyClass : public QObject
{
public:
MyClass( const string &text, QObject *parent = 0 );

const string &text();
void setText( const string &text );

int getLengthOfText();

private:
string m_text;
};

MyClass::MyClass( const string &text, QObject *parent ) : QObject( parent )
{
m_text = text;
}
const string &MyClass::text() { return m_text; }
void MyClass::setText( const string &text ) { m_text = text; }
int MyClass::getLengthOfText() { return m_text.size(); }

int main( int argc, char **argv )
{
QObject parent;
MyClass *a, *b, *c;

a = new MyClass( "foo", &parent );
b = new MyClass( "ba-a-ar", &parent );
c = new MyClass( "baz", &parent );

qDebug() << QString::fromStdString(a->text()) << " (" << a->getLengthOfText() << ")";
a->setText( b->text() );
qDebug() << QString::fromStdString(a->text()) << " (" << a->getLengthOfText() << ")";

return a->getLengthOfText() - c->getLengthOfText();
}
13 changes: 13 additions & 0 deletions Chapter01/cpp-with-qobject/example.pro
@@ -0,0 +1,13 @@
######################################################################
# Automatically generated by qmake (2.00a) ti 8. aug 18:09:23 2006
######################################################################

TEMPLATE = app
TARGET +=
DEPENDPATH += .
INCLUDEPATH += .

# Input
SOURCES += cpp-with-qobject.cpp

CONFIG += console
73 changes: 73 additions & 0 deletions Chapter01/cpp-with-qstring/cpp-with-qstring.cpp
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2006-2007, Johan Thelin
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of APress nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/

#include <QObject>
#include <QtDebug>

#include <QString>

class MyClass : public QObject
{
public:
MyClass( const QString &text, QObject *parent = 0 );

const QString &text();
void setText( const QString &text );

int getLengthOfText();

private:
QString m_text;
};

MyClass::MyClass( const QString &text, QObject *parent ) : QObject( parent )
{
m_text = text;
}
const QString &MyClass::text() { return m_text; }
void MyClass::setText( const QString &text ) { m_text = text; }
int MyClass::getLengthOfText() { return m_text.size(); }

int main( int argc, char **argv )
{
QObject parent;
MyClass *a, *b, *c;

a = new MyClass( "foo", &parent );
b = new MyClass( "ba-a-ar", &parent );
c = new MyClass( "baz", &parent );

qDebug() << a->text() << " (" << a->getLengthOfText() << ")";
a->setText( b->text() );
qDebug() << a->text() << " (" << a->getLengthOfText() << ")";

return a->getLengthOfText() - c->getLengthOfText();
}
13 changes: 13 additions & 0 deletions Chapter01/cpp-with-qstring/example.pro
@@ -0,0 +1,13 @@
######################################################################
# Automatically generated by qmake (2.00a) to 10. aug 14:07:53 2006
######################################################################

TEMPLATE = app
TARGET +=
DEPENDPATH += .
INCLUDEPATH += .

# Input
SOURCES += cpp-with-qstring.cpp

CONFIG += console
13 changes: 13 additions & 0 deletions Chapter01/gui-connection/example.pro
@@ -0,0 +1,13 @@
######################################################################
# Automatically generated by qmake (2.00a) sö 13. aug 19:59:30 2006
######################################################################

TEMPLATE = app
TARGET +=
DEPENDPATH += .
INCLUDEPATH += .

# Input
HEADERS += myclass.h
SOURCES += gui-connection.cpp myclass.cpp
CONFIG += console
65 changes: 65 additions & 0 deletions Chapter01/gui-connection/gui-connection.cpp
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2006-2007, Johan Thelin
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of APress nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/

#include "myclass.h"

#include <QApplication>
#include <QWidget>
#include <QVBoxLayout>
#include <QLabel>
#include <QLineEdit>

int main( int argc, char **argv )
{
QApplication app( argc, argv );

QWidget widget;
QLineEdit *lineEdit = new QLineEdit();
QLabel *label = new QLabel();

QVBoxLayout *layout = new QVBoxLayout();
layout->addWidget( lineEdit );
layout->addWidget( label );
widget.setLayout( layout );

MyClass *bridge = new MyClass( "", &app );

QObject::connect(
lineEdit, SIGNAL(textChanged(const QString&)),
bridge, SLOT(setText(const QString&)) );
QObject::connect(
bridge, SIGNAL(textChanged(const QString&)),
label, SLOT(setText(const QString&)) );

widget.show();

return app.exec();
}
56 changes: 56 additions & 0 deletions Chapter01/gui-connection/myclass.cpp
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2006-2007, Johan Thelin
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of APress nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/

#include "myclass.h"

MyClass::MyClass( const QString &text, QObject *parent ) : QObject( parent )
{
m_text = text;
}

const QString &MyClass::text() const
{
return m_text;
}

void MyClass::setText( const QString &text )
{
if( m_text == text )
return;

m_text = text;
emit textChanged( m_text );
}

int MyClass::getLengthOfText() const
{
return m_text.size();
}

0 comments on commit 3a07989

Please sign in to comment.