Blog Archives

How to Convert int to QString

QString::number(int)

Tagged with: ,
Posted in QT

Qt How to Get Current Date and Time in Qt

Get Current Date in custom Format with Qt QString date = QDate::currentDate().toString(“dd.MM.yyyy”); Get Current Date and Time in Custom Format with Qt QString time = QDateTime::currentDateTime().toString(“dd.MM.yyyy hh:mm”);

Tagged with: , ,
Posted in QT

Adding Context Menu in Qt Application

Qt Context Menu Item item = new QAction(QIcon(“icon_image.png”), “Item Name”, this); connect(item, SIGNAL(triggered()), this, SLOT(on_actionTaken_clicked())); this->ui->tableView->addAction(item); this->ui->tableView->setContextMenuPolicy(Qt::ActionsContextMenu);

Tagged with: , ,
Posted in QT

Qt Get tableView Column Name

Get tableView Column Name Code Snippet this->db->model->headerData(     this->ui->tableView->selectionModel()->currentIndex().column(),     Qt::Horizontal,     0).toString()

Tagged with: , ,
Posted in QT

Qt Sql Databse Connection

Sql Database Connection code snippet QSqlDatabase db = QSqlDatabase::addDatabase(“QODBC”); db.setHostName(“HOST_NAME”); db.setDatabaseName(“database_name”); db.setUserName(“db_user”); db.setPassword(“db_password”); bool ok = db.open();if(ok){ // Houston we have connection! } In order this to work you have to create ODBC connection in Control Panel/Administrative Tools/ODBC Data Source

Tagged with: , ,
Posted in QT

Qt PushButton background image

Create button Create QPushButton in QtCreator. I hope you know how to do that. If not reference the documentation. Program desired action and add this to assign the image in the mainwindow.cpp QStringstyleButton1;    styleButton1.append(“QPushButton{background-image:url(‘bgimage.png’);background-repeat:no-repeat;background-position:top100%;}”); ui->pushButton1->setStyleSheet(styleButton1); Create image The image

Tagged with: , , ,
Posted in QT

Qt Get tableView Cell Value

Get Cell Value in Qt tableView Code Snippet this->db->model->data(     this->db->model->index(         this->ui->tableView->selectionModel()->currentIndex().row(),         this->ui->tableView->selectionModel()->currentIndex().column()).toString());

Tagged with: ,
Posted in QT

Qt Set Header Name in tableView

Set tableView Header Name Code Snippet this->db->model->setHeaderData(0, Qt::Horizontal, QObject::tr(“column_name”));

Tagged with: , ,
Posted in QT

Qt Error collect2 – ld returned 1 exit status

Description collect2: ld returned 1 exit status appear when trying to build Qt application. the error appear because there is signal/slot of an object that I delete (QPushButton). Solution QtCreator didn’t delete the signals automatically when you delete some object

Tagged with: ,
Posted in QT

QSqlDatabase – No Such File or Directory

This error appear when trying to compile Qt Creator project and using SQL database connection. Two things are a must: #include <QSqlDatabase> in the beggining of the file QT += sql in the .pro file

Tagged with: ,
Posted in QT
Sites
Categories
Archives