How to Install OpenCV in Ubuntu 18.04 LTS for C / C++ (Linux)
In this post we will see How to Install OpenCV in Ubuntu for C/C++ OpenCV is an image processing library […]
C++ Tutorial for Beginners – Learning C++ in simple and easy steps : A beginner’s tutorial containing complete knowledge of C++ Syntax Object Oriented Language, Methods, Overriding, Inheritance, Polymorphism, Interfaces, STL, Iterators, Algorithms, Exception Handling, Overloading,Templates, Namespaces and Signal Handling
In this post we will see How to Install OpenCV in Ubuntu for C/C++ OpenCV is an image processing library […]
SQLite C/C++ – CREATE Table in SQLite Database using C/C++ SQLite C/C++- CREATE Table in SQLite Database using C/C++ […]
SQLite C/C++- CREATE and OPEN SQLite Database using C/C++ Make a C Program file and Name it as main.c […]
In this post we will see How to Install OpenCV in Ubuntu for C/C++ OpenCV is an image processing library […]
MinGW, a contraction of “Minimalist GNU for Windows”, is a minimalist development environment for native Microsoft Windows applications. Downloading MinGW open […]
qt notepad design QtNotepadDemo.pro
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#------------------------------------------------- # # Project created by QtCreator 2016-05-26T17:28:11 # #------------------------------------------------- QT += core gui printsupport greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = QtNotepadDemo TEMPLATE = app SOURCES += main.cpp\ mainwindow.cpp HEADERS += mainwindow.h FORMS += mainwindow.ui RESOURCES += \ resource.qrc |
mainwindow.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); private slots: void on_actionNew_triggered(); void on_actionCopy_triggered(); void on_actionOpen_triggered(); void on_actionSave_triggered(); void on_actionSave_as_triggered(); void on_actionCut_triggered(); void on_actionPaste_triggered(); void on_actionRedo_triggered(); void on_actionUndo_triggered(); void on_actionAbout_Notepad_triggered(); void on_actionFont_triggered(); void on_actionColor_triggered(); void on_actionBackground_Color_triggered(); void on_actionBackgroung_Color_Edit_Text_triggered(); void on_actionPrint_triggered(); private: Ui::MainWindow *ui; QString file_path_; }; #endif // MAINWINDOW_H |
mainwindow.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QFile> #include <QFileDialog> #include <QTextStream> #include <QMessageBox> #include <QFontDialog> #include <QFont> #include <QColorDialog> #include <QColor> #include <QPrinter> #include <QPrintDialog> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); this->setCentralWidget(ui->textEdit); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_actionNew_triggered() { file_path_ = ""; ui->textEdit->setText(""); } void MainWindow::on_actionCopy_triggered() { ui->textEdit->copy(); } void MainWindow::on_actionOpen_triggered() { QString file_name = QFileDialog::getOpenFileName(this,"Open the file"); QFile file(file_name); file_path_ = file_name; if(!file.open(QFile::ReadOnly | QFile::Text)) { QMessageBox::warning(this,"..","file not open"); return; } QTextStream in(&file); QString text = in.readAll(); ui->textEdit->setText(text); file.close(); } void MainWindow::on_actionSave_triggered() { QFile file(file_path_); if(!file.open(QFile::WriteOnly | QFile::Text)) { QMessageBox::warning(this,"..","file not open"); return; } QTextStream out(&file); QString text = ui->textEdit->toPlainText(); out << text; file.flush(); file.close(); } void MainWindow::on_actionSave_as_triggered() { QString file_name = QFileDialog::getSaveFileName(this,"Open the file"); QFile file(file_name); file_path_ = file_name; if(!file.open(QFile::WriteOnly | QFile::Text)) { QMessageBox::warning(this,"..","file not open"); return; } QTextStream out(&file); QString text = ui->textEdit->toPlainText(); out << text; file.flush(); file.close(); } void MainWindow::on_actionCut_triggered() { ui->textEdit->cut(); } void MainWindow::on_actionPaste_triggered() { ui->textEdit->paste(); } void MainWindow::on_actionRedo_triggered() { ui->textEdit->redo(); } void MainWindow::on_actionUndo_triggered() { ui->textEdit->undo(); } void MainWindow::on_actionAbout_Notepad_triggered() { QString about_text; about_text = "Auther : somebody\n"; about_text += "Date : 12/05/2016\n"; about_text += "(C) Notepad (R)\n"; QMessageBox::about(this,"About Notepad",about_text); } void MainWindow::on_actionFont_triggered() { bool ok; QFont font = QFontDialog::getFont(&ok, this); if (ok) { ui->textEdit->setFont(font); } else return; } void MainWindow::on_actionColor_triggered() { QColor color = QColorDialog::getColor(Qt::white,this,"Choose Color"); if(color.isValid()) { ui->textEdit->setTextColor(color); } } void MainWindow::on_actionBackground_Color_triggered() { QColor color = QColorDialog::getColor(Qt::white,this,"Choose Color"); if(color.isValid()) { ui->textEdit->setTextBackgroundColor(color); } } void MainWindow::on_actionBackgroung_Color_Edit_Text_triggered() { QColor color = QColorDialog::getColor(Qt::white,this,"Choose Color"); if(color.isValid()) { ui->textEdit->setPalette(QPalette(color)); } } void MainWindow::on_actionPrint_triggered() { QPrinter printer; printer.setPrinterName("desierd printer name"); QPrintDialog dialog(&printer,this); if(dialog.exec() == QDialog::Rejected) return; ui->textEdit->print(&printer); } |
main.cpp
1 2 3 4 5 6 7 8 9 10 11 |
#include "mainwindow.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); } |
mainwindow.ui
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>MainWindow</class> <widget class="QMainWindow" name="MainWindow"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>513</width> <height>361</height> </rect> </property> <property name="windowTitle"> <string>MainWindow</string> </property> <widget class="QWidget" name="centralWidget"> <layout class="QHBoxLayout" name="horizontalLayout"> <item> <widget class="QTextEdit" name="textEdit"/> </item> </layout> </widget> <widget class="QMenuBar" name="menuBar"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>513</width> <height>21</height> </rect> </property> <widget class="QMenu" name="menuFile"> <property name="title"> <string>File</string> </property> <addaction name="actionNew"/> <addaction name="actionOpen"/> <addaction name="separator"/> <addaction name="actionSave"/> <addaction name="actionSave_as"/> <addaction name="separator"/> <addaction name="actionPrint"/> </widget> <widget class="QMenu" name="menuEdit"> <property name="title"> <string>Edit</string> </property> <addaction name="actionCut"/> <addaction name="actionCopy"/> <addaction name="actionPaste"/> <addaction name="separator"/> <addaction name="actionRedo"/> <addaction name="actionUndo"/> <addaction name="separator"/> <addaction name="actionFont"/> <addaction name="actionColor"/> <addaction name="actionBackground_Color"/> <addaction name="actionBackgroung_Color_Edit_Text"/> </widget> <widget class="QMenu" name="menuAbout"> <property name="title"> <string>about</string> </property> <addaction name="actionAbout_Notepad"/> </widget> <addaction name="menuFile"/> <addaction name="menuEdit"/> <addaction name="menuAbout"/> </widget> <widget class="QToolBar" name="mainToolBar"> <attribute name="toolBarArea"> <enum>TopToolBarArea</enum> </attribute> <attribute name="toolBarBreak"> <bool>false</bool> </attribute> <addaction name="actionNew"/> <addaction name="actionOpen"/> <addaction name="actionSave"/> <addaction name="actionSave_as"/> <addaction name="separator"/> <addaction name="actionCut"/> <addaction name="actionCopy"/> <addaction name="actionPaste"/> <addaction name="separator"/> <addaction name="actionRedo"/> <addaction name="actionUndo"/> <addaction name="separator"/> <addaction name="actionAbout_Notepad"/> </widget> <widget class="QStatusBar" name="statusBar"/> <action name="actionNew"> <property name="icon"> <iconset resource="resource.qrc"> <normaloff>:/rec/img/new.png</normaloff>:/rec/img/new.png</iconset> </property> <property name="text"> <string>New</string> </property> </action> <action name="actionOpen"> <property name="icon"> <iconset resource="resource.qrc"> <normaloff>:/rec/img/open.png</normaloff>:/rec/img/open.png</iconset> </property> <property name="text"> <string>Open</string> </property> </action> <action name="actionSave"> <property name="icon"> <iconset resource="resource.qrc"> <normaloff>:/rec/img/save.png</normaloff>:/rec/img/save.png</iconset> </property> <property name="text"> <string>Save</string> </property> </action> <action name="actionSave_as"> <property name="icon"> <iconset resource="resource.qrc"> <normaloff>:/rec/img/save-as.png</normaloff>:/rec/img/save-as.png</iconset> </property> <property name="text"> <string>Save as</string> </property> </action> <action name="actionCut"> <property name="icon"> <iconset resource="resource.qrc"> <normaloff>:/rec/img/cut.png</normaloff>:/rec/img/cut.png</iconset> </property> <property name="text"> <string>Cut</string> </property> </action> <action name="actionCopy"> <property name="icon"> <iconset resource="resource.qrc"> <normaloff>:/rec/img/copy.png</normaloff>:/rec/img/copy.png</iconset> </property> <property name="text"> <string>Copy</string> </property> </action> <action name="actionPaste"> <property name="icon"> <iconset resource="resource.qrc"> <normaloff>:/rec/img/paste.png</normaloff>:/rec/img/paste.png</iconset> </property> <property name="text"> <string>Paste</string> </property> </action> <action name="actionRedo"> <property name="icon"> <iconset resource="resource.qrc"> <normaloff>:/rec/img/redo.png</normaloff>:/rec/img/redo.png</iconset> </property> <property name="text"> <string>Redo</string> </property> </action> <action name="actionUndo"> <property name="icon"> <iconset resource="resource.qrc"> <normaloff>:/rec/img/undo.png</normaloff>:/rec/img/undo.png</iconset> </property> <property name="text"> <string>Undo</string> </property> </action> <action name="actionAbout_Notepad"> <property name="icon"> <iconset resource="resource.qrc"> <normaloff>:/rec/img/about.png</normaloff>:/rec/img/about.png</iconset> </property> <property name="text"> <string>About Notepad</string> </property> </action> <action name="actionFont"> <property name="text"> <string>Font</string> </property> </action> <action name="actionColor"> <property name="text"> <string>Color</string> </property> </action> <action name="actionBackground_Color"> <property name="text"> <string>Background Color</string> </property> </action> <action name="actionBackgroung_Color_Edit_Text"> <property name="text"> <string>Backgroung Color Edit Text</string> </property> </action> <action name="actionPrint"> <property name="text"> <string>Print</string> </property> </action> </widget> <layoutdefault spacing="6" margin="11"/> <resources> <include location="resource.qrc"/> </resources> <connections/> </ui> |
resource.qrc
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<RCC> <qresource prefix="/rec"> <file>img/about.png</file> <file>img/copy.png</file> <file>img/cut.png</file> <file>img/new.png</file> <file>img/open.png</file> <file>img/paste.png</file> <file>img/redo.png</file> <file>img/save.png</file> <file>img/save-as.png</file> <file>img/undo.png</file> </qresource> </RCC> |
output
C++ Program to Convert Integer into a String
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
using namespace std; #include <string> #include <sstream> #include <iostream> template <class T> std::string to_string(T t, std::ios_base & (*f)(std::ios_base&)) { std::ostringstream oss; oss << f << t; return oss.str(); } int main() { // the second parameter of to_string() should be one of // std::hex, std::dec or std::oct std::cout<<to_string<long>(123456, std::hex)<<std::endl; std::cout<<to_string<long>(123456, std::oct)<<std::endl; return 0; } /* OUTPUT: 1e240 361100 */ |
C++ Function To Convert String To Numeric Integer
1 2 3 4 5 6 7 8 |
float stof(const string& str, size_t *idx = 0); double stod(const string& str, size_t *idx = 0); long double stold(const string& str, size_t *idx = 0); int stoi(const string& str, size_t *idx = 0, int base = 10); long stol(const string& str, size_t *idx = 0, int base = 10); unsigned long stoul(const string& str, size_t *idx = 0, int base = 10); long long stoll(const string& str, size_t *idx = 0, int base = 10); unsigned long long stoull(const string& str, size_t *idx = 0, int base = 10); |
C++ Function […]
C++ Program to convert hexadecimal to decimal with std::hex
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
/** * Converting Hexadecimal to Decimal in C++ codebind.com * */ #include <iostream> int main() { int integer; std::cout<<"Entex Hex to Convert hex to decimal"<<std::endl; std::cin >> std::hex >> integer; std::cout << integer << std::endl; return 0; } /* OUTPUT: Entex Hex to Convert hex to decimal 10 16 */ |
C++ Program to convert hexadecimal to decimal without std::hex
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
/** * Converting Hexadecimal to Decimal in C++ codebind.com * */ #include<iostream> #include<stdlib.h> #include<conio.h> #include<math.h> unsigned long HexToDec(char hex[]) { char *hexstr; int length = 0; const int base = 16; // Base of Hexadecimal Number unsigned long decnum = 0; int i; // Now Find the length of Hexadecimal Number for (hexstr = hex; *hexstr != '\0'; hexstr++) { length++; } // Now Find Hexadecimal Number hexstr = hex; for (i = 0; *hexstr != '\0' && i < length; i++, hexstr++) { // Compare *hexstr with ASCII values if (*hexstr >= 48 && *hexstr <= 57) { // is *hexstr Between 0-9 decnum += (((int)(*hexstr)) - 48) * pow(base, length - i - 1); } else if ((*hexstr >= 65 && *hexstr <= 70)) { // is *hexstr Between A-F decnum += (((int)(*hexstr)) - 55) * pow(base, length - i - 1); } else if (*hexstr >= 97 && *hexstr <= 102) { // is *hexstr Between a-f decnum += (((int)(*hexstr)) - 87) * pow(base, length - i - 1); } else { std::cout<<"Invalid Hexadecimal Number \n"; } } return decnum; } void main() { unsigned long decnum; char hex[9]; // 8 characters for 32-bit Hexadecimal Number and one for ' ' std::cout<<" Enter 32-bit Hexadecimal Number : "; std::cin>>hex; decnum = HexToDec(hex); std::cout<<"Value in Decimal Number is "<<decnum<<"\n"; getch(); } /* OUTPUT: Enter 32-bit Hexadecimal Number : 10 Value in Decimal Number is 16 */ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
/** * CONVERTING BINARY TO DECIMAL IN C++ codebind.com * */ #include <iostream> #include <iomanip> #include <string> #include <climits> using namespace std; const size_t maxBits = sizeof(short) * CHAR_BIT; int main(int argc, char *argv[]) { string line; bool inputOk; short n; while (true) { cout << "Enter binary number (" << maxBits; cout << " bits or less) : " << endl; do { cout << "> "; getline(cin,line); inputOk = true; for (size_t i = 0; (i < line.size()) && (inputOk == true); i++) { if ((line[i] != '0') && (line[i] != '1')) { inputOk = false; cout << "non-bit entered" << endl; } } if ((inputOk == true) && (line.size() > maxBits)) { inputOk = false; cout << "too big for " << maxBits << "-bit integer" << endl; } } while (inputOk == false); // Convert string of bits to an integer n = 0; for (int i = line.size()-1, j = 0; i >= 0; --i,j++) { n |= (line[i] - '0') << j; } cout << line << " = " << n << endl; } return 0; } /* OUTPUT: Enter binary number (16 bits or less) : > 101000 101000 = 40 Enter binary number (16 bits or less) : > 10 10 = 2 Enter binary number (16 bits or less) : > 10 10 = 2 Enter binary number (16 bits or less) : > 101 101 = 5 Enter binary number (16 bits or less) : > */ |
Different ways of Putting the above question Binary To Decimal Conversion in C++ Convert Binary to Decimal and from […]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
/** * CONVERT A DECIMAL TO OCTAL IN C++ codebind.com * */ #include <iostream> #include<cmath> using namespace std; void DecToOct(int decnum){ int digits=1; int howbig=1; // check to see how many digits while(1){ if((8*howbig)>decnum){ break; }else{ howbig*=8; digits++; } } // using binary to get octal for(int i=digits;i>0;i--) cout<<((decnum>>((i-1)*3))&7); } void DecToQuat(int decnum){ int digits=1; int howbig=1; // check to see how many digits while(1){ if((4*howbig)>decnum){ break; }else{ howbig*=4; digits++; } } // using binary to get quat for(int i=digits;i>0;i--) cout<<((decnum>>((i-1)*2))&3); } int main(){ int decimalnum; cout<<"Enter the decimal to be converted:"; cin>>decimalnum; DecToOct(decimalnum); cout<<endl; DecToQuat(decimalnum); return 0; } /* OUTPUT Enter the decimal to be converted:16 20 */ |
Different ways of Putting the above question What’s an easy way to convert a Decimal to Octal in C++? […]
Introduction You are apparently somehow stumbled upon the language C ++. I will here shed light on why it is […]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
#include<iostream> using namespace std; int Factorial(int n){ static int i=1;// to make one time initialization cout<<i<<" : time"<<endl; // counting the function calls if(n==1){ return 1;//base case } else{ i++; return n=n*Factorial(n-1); } } int main(){ cout<<"Enter to number to find Factorial: "; int num; cin>>num; num=Factorial(num); // function call cout<<"\nFactorial of number is: "<<num << endl; return 0; } /* OUTPUT Enter to number to find Factorial: 5 1 : time 2 : time 3 : time 4 : time 5 : time Factorial of number is: 120 */ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#include<iostream> using namespace std; int main() { int number, reverse = 0; cout<<"Enter a Number to Reverse and press Enter: "; cin>> number; // Taking Input Number in variable number for( ; number!= 0 ; ) { reverse = reverse * 10; reverse = reverse + number%10; number = number/10; } cout<<"Reversed Number is: "<< reverse; return 0; } /* OUTPUT Enter a Number to Reverse and press Enter: 123456789 Reversed Number is: 987654321 */ |
In this post we will see how to add the click event to the QPushbutton with an example. samples.pro
1 2 3 4 5 6 7 8 9 10 |
TARGET = Sample QT = core gui CONFIG += c++11 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets SOURCES += \ main.cpp HEADERS += \ MyMainWindow.h |
In this post we will see how to write C++ Program list all files in the Directory on Windows and […]
Copyright © 2021 | WordPress Theme by MH Themes