[Qt C++] – Transparent, dynamically generated from text tray icon

#include <QApplication>
 
#include <QSystemTrayIcon>
#include <QPixmap>
#include <QPainter>
#include <QFont>
 
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
 
    QPixmap pixmap(20, 20); // small size should work fine on every platform
    pixmap.fill(Qt::transparent); // set transparency of the icon
 
    QPainter painter(&pixmap);
 
    int size = 15;  // size 15 looks nice on KDE and GNOME
    QFont font("", size);
 
    painter.setFont(font);
 
    QString theText = "3"; // this will be the text in the system tray icon
    painter.drawText(QPoint(5, size+1), theText);
 
    QSystemTrayIcon *tray = new QSystemTrayIcon();
    tray->setIcon(QIcon(pixmap));
    tray->show();
 
    return app.exec();
}

Continue reading

Just a quick fix.

Instead of:

Connection con = null;
 
String url = "jdbc:mysql://localhost:3306/mysql";
String user = "user";
String password = "password";
con = DriverManager.getConnection(url, user, password);

You should have:

Connection con = null;
 
String url = "jdbc:mysql://localhost:3306/mysql";
String user = "user";
String password = "password";
 
try {
    Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception ex) {
    System.err.println(ex.getMessage());
}
con = DriverManager.getConnection(url, user, password);

Continue reading

I had to write this application as a university project.

The task was to generate a word ladder, which starts and ends on provided words. Both words have to be in a dictionary.

Every single step in the ladder must only differ in one character from the word before. The aim of the word-ladder is to find the shortest path from start word to end word in the whole graph.

Continue reading