- SVN Repo at blackhawk.ece.uah.edu:
/home/work/cpe353-20f/team6/ffflamingos
hereafter, the SVN repo base dir will be referred to asffflamingos
- How to use SVN
- See also
- Warning Do Not run the svnadmin create command!
-
Doxygen documentation at
./docs/index.html
. This provides you with a high level documentation of the code base. -
Style Guidelines - To be enforced by the
clang-format
utility. -
How to rebuild documentation before a check in
./docnclean.sh
- Remember to include the line
Q_OBJECT
in the class declaration.
connect(
address of object emitting the signal,
SIGNAL,
address of the object to respond to that particular signal,
SLOT
)
The signals and slots are macros that are expanded by the inner workings of QT. They are represented as follows:
SIGNAL(clicked(bool))
SLOT(handleEvent(bool))
The signals and slots are handled by passing the address in C++ form of the appropriate signal and slot functions:
&QPushButton::clicked
&SomeClass:handlEvent
The following returns the address of the setNum function that takes the int argument:
static_cast<void (QLabel::*)(int)>(&QLabel::setNum)
More can be found at Signals & Slots
- Modal blocks interaction from the rest of the program until you are finished.
myDialog.exec()
- NonModal Lets you continue interaction with the rest of the program
myDialog.show()
Some more dialog windows can be seen at Dialog Windows
Input validation is often most easily done using a QRegularExpressionValidator
. This looks as follows:
QRegularExpressionValidator* validatorName = new QRegularExpressionValidator(QRegularExpression("[0-9]{3}"));
someString.setValidator(validatorName);
You may also need to process only numerical input. This is most easily done through QIntValidator
QIntValidator* validatorName = new QIntValidator(0,999, someString);
someString.setValidator(validatorName);
More can be found at Qt Quick Text Input Handling and Validators
The tool bar is used by adding QAction
to it. See QAction
.
The tool bar lets you have drag and drop functionality by default. This can be handy when you're trying to implement tools that should be readily available to the user.
action1 = new QAction(...);
someToolBar->addAction(action1);
More can be found at QToolBar
The menu bar also takes QAction
and implements the typical File
, Edit
, View
, ...
on normal windows.
action1 = new QAction(...);
actionMenu = menuBar()->addMenu("&Actions");
actionMenu->addAction(action1);
actionMenu->addSeparator();
More can be found at QMenuBar
QLabel* statusLabel = new QLabel("Ready");
statusBar()->addWidget(statusLabel);
More can be found at QStatusBar
We commonly use the following types of Containers:
QTabWidget
Other containers can be found at Containers
You may need to implement either the general or specific event handler of an event handler to get the functionality that you desire. It is always preferred to mess with the most specific event handler possible.
void MainWindow::keyPressEvent(QKeyEvent * key) {
if (key && key->key() == Qt::Key_Escape) {
bool ok;
int count = status->text().toInt(&ok);
if (ok) {
count++;
status->setNum(count);
}
else {
qDebug() << "BAD BOI";
}
}
}
bool MainWindow::event(QEvent * e) {
if (e && e->type() == QEvent::KeyPress) {
QKeyEvent * key = static_cast<QKeyEvent*>(e);
if (key->key() == Qt::Key_Escape) {
qDebug() << "Escape";
}
}
return QMainWindow::event(e);
}
Notice how the general event handler passes the puck to QMainWindow::event(e)
if the MainwWindow::event(e)
call did not need to prcoess that specific event.
More can be found at The Event System.
WARNING Paths that are relative attempt to open from the build directory.
QFile somefile("filename.txt");
if(somefile.exists()) // Returns a boolean
somefile.open(QIODevice::ReadOnly | QIODevice::Text);
Notice the Logical or to combine properties. Common properties are as follows:
QIODevice::ReadOnly
QIODevice::WriteOnly
QIODevice::ReadWrite
QIODevice::Truncate
Deletes Previous ContentsQIODevice::Append
Adds to existing contentsQIODevice::Text
Use OS specific EOL
Remember, for Data streams you can choose to overload the >>
and <<
operators. The example below shows writing out using the student method discussed in Qt010.
For the following, we are using a QDataStream
QFile outFile( "sample.txt" );
outFile.open( QIODevice::WriteOnly)
QDataStream outStream(&outFile);
outStream.setVersion( QDataStream::Qt_4_1);
outStream<< student1 << student2 << student3;
outFile.close();
The following shows a similar type example but for Text Streams. These are easier to debug although they require more space to store.
QFile outFile( "sample.txt" );
outFile.open( QIODevice::WriteOnly);
QTextStream someStream(&outFile);
someStream << "someString";
outFile.close();
More can be found at File and Datastream Functions
QUdpSocket * socket = new QUdpSocket;
connect(socket, &QUdpSocket::readyRead, this, someClass::someHandler);
socket->bind(QHostAddress::LocalHost, 5678);
The handler would look something like this:
QByteArray datagram;
while (socket->hasPendingDatagrams()) {
datagram.resize(socket->pendingDatagramSize());
socket->readDatagram(datagram.data(), datagram.size());
QTextStream in(&dattagram);
QString msg = in.readAll();
msg = msg.trimmed();
// Then put the QString where you need it.
}
myTCPSocket = new QTcpSocket; // Allocate a new QTcpSocket
myTCPSocket->setProxy(QNetworkProxy::NoProxy); // Avoid using a proxy if the system defaults to one
connect(
myTCPSocket,
&QTcpSocket::readyRead,
this,
&MainWindow::processPendingData
); // Form the connection between the TCP socket and the handler
myTCPSocket->connectToHost(
QHostAddress::LocalHost,
5678,
QIODevice::ReadOnly
); // Attempt to connect to a device on incoming port 5678
myTCPSocket->waitForConnected(); // Stays in program loop until a TCP connection is established
Where the processPendingData
would look something like this:
void MainWindow::processPendingData() {
QByteArray data = myTCPSocket->readAll(); // Allocate the memory of the size of the new line and read it in
QString msg(data); // Type cast the QByteArray into a QString
qDebug() << msg.trimmed(); // Write out the message to debug
ui->textBrowser->append(msg.trimmed()); // Append this wherever it needs to be
}
More can be found on Networking and Connectivity. More can be found on QtNetwork C++ Classes
For QLabels:
- Create
class CustomLabel : public QLabel
Function | Destination | Source |
---|---|---|
dragEnterEvent(...) |
Y | N |
dropEvent(...) |
Y | N |
mousePressEvent(...) |
N | Y |
-
Reimplement
void dragEnterEvent(QDragEnterEvent* event);
void Label::dragEnterEvent(QDragEnterEvent* event) { if (event && event->mimeData()) { const QMimeData* md = event->mimeData(); if(md->hasImage()) { // Handle your MimeData as needed event->acceptProposedAction(); } } QLabel::dragEnterEvent(event); }
-
Reimplement
void dropEvent(QDropEvent* event);
void Label::dropEvent(QDropEvent* event) { QPixmap pic; if (event && event->mimeData()) { const QMimeData* md = event->mimeData(); if (md->hasImage()) { // Handle your mimeData as needed pic = md->imageData().value<QPixmap>(); } } QLabel::dropEvent(event); }
-
Reimplement
void mousePressEvent(QMouseEvent* event);
void Label::mousePressEvent(QMouseEvent *event) { if(event && event->button() == Qt::LeftButton) { // Allocate and initialize Mimedata object QMimeData* md = new QMimeData; md->setImageData(*this->pixmap()); QDrag* drag = new QDrag(this); drag->setMimeData(md); if (pixmap()) { drag->start(); } } }
More can be found on the Drag and Drop page.
Data resides in the model while you may have multiple views of this data.
QStringListModel
Viewed byQListView
QTableView
QTreeView
QColumnView
Using the following:
QListView listView;
QStringList list;
QStringListModel model;
listView.setModel(&model);
list.append("someNewString);
model.setStringList(list);
More can be found on the Graphics View Documentation.
This can be enabled via
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
See more on the usage of Logical COordinates on the Qt Docs Coordinate System page.
A QComboBox
is interected to by making appending QStrings to the values.
QComboBox someBox;
QStringList someList;
someList.append("Help");
someList.append("ME");
someBox.addItems(someList);
size()
setPermissions(...)
permissions()
rename(...)
remove(...)
exists(...)
copy(...)
atEnd()
Also, note that similar things can be used forQDir
.
current()
returns current working directoryhome()
returns user home directoryexists()
filePath()
returns filename including pathabsoluteFilePath()
root()
cd(...)
cdUp()
isAbsolute()
isRelative()
makeAbsolute()
forces conversion to absolute path
- Holds
QString
orQPixmap
. .setText(QString)
.setPixmap(QPixmap)
- Interact with
clear
setText