QString::number(int)
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”);
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);
Get tableView Column Name Code Snippet this->db->model->headerData( this->ui->tableView->selectionModel()->currentIndex().column(), Qt::Horizontal, 0).toString()
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…
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…
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());
Set tableView Header Name Code Snippet this->db->model->setHeaderData(0, Qt::Horizontal, QObject::tr(“column_name”));
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…
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