Code Snippets

// Regular Expressions
QRegExp rx("^(Border|Text|Shape|Graphic)$");
if (rx.exactMatch(objectName) == true){
    // do something
}


// QString with arguments
statusBar()->showMessage(tr("Position: (%1,%2) in top level").arg(row).arg(column));
QString newTemplate = QString("New Template %1").arg(newTemplateCount);


// Algorithm to walk a tree structure
void DataModel::walkTree(const QModelIndex &row)
{
    if (this->hasChildren()) {
        for (int i = 0; i < rowCount(row); ++i){
            walkTree(this->index(i,0,row));
        }
    }
}



// 2 dimensional QVector
QVector< QVector< int > > twoDArray;      // Empty.
QVector< QVector< int > > twoDArray( 2 ); // Contains two int arrays.
twoDArray[0].resize(4);
twoDArray[0][2] = 4;  // Assign to the third element of the first array.