C++ - instalación y configuración en Ubuntu
📘 Documentación Oficial ### ⭐ Frameworks populares (ordenados de menor a mayor curva de aprendizaje) ### 🛠️ Instalación de C++ en Ubuntu ### 🍺 Instalación con Homebrew ### 📦 Gestor de paquetes estándar ### 🔧 Instalación con ASDF ### 📝▶️ Crear y ejecutar un archivo C++ ## 🟦 Ejemplo básico en C++ ### 🗂️🌐 Servidor Web de archivos estáticos. ### ⚙️🧩 API REST JSON ## 🟦 Ejemplo extra en C++ ### 💻 Calculadora GUI con QT ### Qué hace: Recomiendo ver antes - instalacion de Homebrew y asdf en ubuntu ( es corto son 5 comandos) ⚠️ En C++ no existen “frameworks web” estándar como en Python, pero sí hay bibliotecas ampliamente usadas. C++ ya viene instalado, pero debes asegurarte de tener g++: C++ no tiene un gestor oficial como pip o npm, pero los más usados son: Ver versión del compilador: Instalar una librería JSON (ejemplo): ASDF puede compilar versiones específicas de GCC/LLVM. Dependencias del sistema: Instalar plugin + versión Ejemplo: .tool-versions Contenido de hello.cpp 💻 Compilar y ejecutar localmente: Nota: C++ no viene con un servidor web integrado.
Pero puedes crear uno muy pequeño usando sockets POSIX (sin dependencias). 📝 Crear archivo: touch server.cpp 📦 Contenido de server.cpp ▶️ Compilar y ejecutar 👉 Visitar:
http://localhost:8000/?username=Homero Archivo ejemplo: data.json 📝 Crear archivo: touch api.cpp ▶️ Contenido del archivo: api.cpp Este ejemplo usa la librería nlohmann/json (solo headers).
Instalar en Ubuntu: ▶️ Compilar y ejecutar 👉 Visitar:
http://localhost:7001/characters Para probar sanitización:
http://localhost:7001/characters/1 Para compilar este archivo en Ubuntu: 📝 Crear archivo: touch qt-calc.cpp ▶️ Contenido del archivo: qt-calc.cpp ▶️ Compilar y ejecutar Templates let you quickly answer FAQs or store snippets for re-use. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse COMMAND_BLOCK:
sudo apt update
sudo apt install g++ build-essential COMMAND_BLOCK:
sudo apt update
sudo apt install g++ build-essential COMMAND_BLOCK:
sudo apt update
sudo apt install g++ build-essential COMMAND_BLOCK:
brew install gcc COMMAND_BLOCK:
brew install gcc COMMAND_BLOCK:
brew install gcc CODE_BLOCK:
g++ --version CODE_BLOCK:
g++ --version CODE_BLOCK:
g++ --version COMMAND_BLOCK:
sudo apt install nlohmann-json3-dev COMMAND_BLOCK:
sudo apt install nlohmann-json3-dev COMMAND_BLOCK:
sudo apt install nlohmann-json3-dev COMMAND_BLOCK:
sudo apt update
sudo apt install -y build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev COMMAND_BLOCK:
sudo apt update
sudo apt install -y build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev COMMAND_BLOCK:
sudo apt update
sudo apt install -y build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev CODE_BLOCK:
asdf plugin add gcc
asdf install gcc 14.1.0
asdf global gcc 14.1.0 CODE_BLOCK:
asdf plugin add gcc
asdf install gcc 14.1.0
asdf global gcc 14.1.0 CODE_BLOCK:
asdf plugin add gcc
asdf install gcc 14.1.0
asdf global gcc 14.1.0 CODE_BLOCK:
touch hello.cpp CODE_BLOCK:
touch hello.cpp CODE_BLOCK:
touch hello.cpp CODE_BLOCK:
#include <iostream>
int main() { std::cout << "Hola Mundo desde C++!\n"; return 0;
} CODE_BLOCK:
#include <iostream>
int main() { std::cout << "Hola Mundo desde C++!\n"; return 0;
} CODE_BLOCK:
#include <iostream>
int main() { std::cout << "Hola Mundo desde C++!\n"; return 0;
} CODE_BLOCK:
g++ hello.cpp -o app-hello
./app-hello CODE_BLOCK:
g++ hello.cpp -o app-hello
./app-hello CODE_BLOCK:
g++ hello.cpp -o app-hello
./app-hello CODE_BLOCK:
#include <iostream>
#include <string>
#include <regex>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h> std::string html_escape(const std::string& text) { std::string escaped = text; escaped = std::regex_replace(escaped, std::regex("&"), "&"); escaped = std::regex_replace(escaped, std::regex("<"), "<"); escaped = std::regex_replace(escaped, std::regex(">"), ">"); escaped = std::regex_replace(escaped, std::regex("\""), """); return escaped;
} int main() { int server = socket(AF_INET, SOCK_STREAM, 0); sockaddr_in addr{}; addr.sin_family = AF_INET; addr.sin_port = htons(8000); addr.sin_addr.s_addr = INADDR_ANY; bind(server, (sockaddr*)&addr, sizeof(addr)); listen(server, 10); std::cout << "Servidor corriendo en http://localhost:8000\n"; while (true) { int client = accept(server, nullptr, nullptr); char buffer[2048] = {0}; read(client, buffer, sizeof(buffer)); std::string request(buffer); // Extraer path size_t start = request.find("GET "); size_t end = request.find(" HTTP/"); std::string path = request.substr(start + 4, end - (start + 4)); // Obtener username std::string username = "guest"; size_t qpos = path.find("?username="); if (qpos != std::string::npos) { username = path.substr(qpos + 10); } username = html_escape(username); // Generar HTML std::string content = "<!DOCTYPE html><html lang='es'><head><meta charset='UTF-8'>" "<title>Hello</title></head><body style='text-align:center'>" "<h1>Hello, " + username + "</h1></body></html>"; std::string response = "HTTP/1.1 200 OK\r\n" "Content-Type: text/html\r\n" "Content-Length: " + std::to_string(content.size()) + "\r\n" "Connection: close\r\n\r\n" + content; send(client, response.c_str(), response.size(), 0); close(client); }
} CODE_BLOCK:
#include <iostream>
#include <string>
#include <regex>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h> std::string html_escape(const std::string& text) { std::string escaped = text; escaped = std::regex_replace(escaped, std::regex("&"), "&"); escaped = std::regex_replace(escaped, std::regex("<"), "<"); escaped = std::regex_replace(escaped, std::regex(">"), ">"); escaped = std::regex_replace(escaped, std::regex("\""), """); return escaped;
} int main() { int server = socket(AF_INET, SOCK_STREAM, 0); sockaddr_in addr{}; addr.sin_family = AF_INET; addr.sin_port = htons(8000); addr.sin_addr.s_addr = INADDR_ANY; bind(server, (sockaddr*)&addr, sizeof(addr)); listen(server, 10); std::cout << "Servidor corriendo en http://localhost:8000\n"; while (true) { int client = accept(server, nullptr, nullptr); char buffer[2048] = {0}; read(client, buffer, sizeof(buffer)); std::string request(buffer); // Extraer path size_t start = request.find("GET "); size_t end = request.find(" HTTP/"); std::string path = request.substr(start + 4, end - (start + 4)); // Obtener username std::string username = "guest"; size_t qpos = path.find("?username="); if (qpos != std::string::npos) { username = path.substr(qpos + 10); } username = html_escape(username); // Generar HTML std::string content = "<!DOCTYPE html><html lang='es'><head><meta charset='UTF-8'>" "<title>Hello</title></head><body style='text-align:center'>" "<h1>Hello, " + username + "</h1></body></html>"; std::string response = "HTTP/1.1 200 OK\r\n" "Content-Type: text/html\r\n" "Content-Length: " + std::to_string(content.size()) + "\r\n" "Connection: close\r\n\r\n" + content; send(client, response.c_str(), response.size(), 0); close(client); }
} CODE_BLOCK:
#include <iostream>
#include <string>
#include <regex>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h> std::string html_escape(const std::string& text) { std::string escaped = text; escaped = std::regex_replace(escaped, std::regex("&"), "&"); escaped = std::regex_replace(escaped, std::regex("<"), "<"); escaped = std::regex_replace(escaped, std::regex(">"), ">"); escaped = std::regex_replace(escaped, std::regex("\""), """); return escaped;
} int main() { int server = socket(AF_INET, SOCK_STREAM, 0); sockaddr_in addr{}; addr.sin_family = AF_INET; addr.sin_port = htons(8000); addr.sin_addr.s_addr = INADDR_ANY; bind(server, (sockaddr*)&addr, sizeof(addr)); listen(server, 10); std::cout << "Servidor corriendo en http://localhost:8000\n"; while (true) { int client = accept(server, nullptr, nullptr); char buffer[2048] = {0}; read(client, buffer, sizeof(buffer)); std::string request(buffer); // Extraer path size_t start = request.find("GET "); size_t end = request.find(" HTTP/"); std::string path = request.substr(start + 4, end - (start + 4)); // Obtener username std::string username = "guest"; size_t qpos = path.find("?username="); if (qpos != std::string::npos) { username = path.substr(qpos + 10); } username = html_escape(username); // Generar HTML std::string content = "<!DOCTYPE html><html lang='es'><head><meta charset='UTF-8'>" "<title>Hello</title></head><body style='text-align:center'>" "<h1>Hello, " + username + "</h1></body></html>"; std::string response = "HTTP/1.1 200 OK\r\n" "Content-Type: text/html\r\n" "Content-Length: " + std::to_string(content.size()) + "\r\n" "Connection: close\r\n\r\n" + content; send(client, response.c_str(), response.size(), 0); close(client); }
} CODE_BLOCK:
g++ server.cpp -o http-server
./http-server CODE_BLOCK:
g++ server.cpp -o http-server
./http-server CODE_BLOCK:
g++ server.cpp -o http-server
./http-server CODE_BLOCK:
[ { "id": 1, "age": 39, "name": "Homer Tompson", "portrait_path": "https://cdn.thesimpsonsapi.com/500/character/1.webp" }, { "id": 2, "age": 39, "name": "Marge Simpson", "portrait_path": "https://cdn.thesimpsonsapi.com/500/character/2.webp" }
] CODE_BLOCK:
[ { "id": 1, "age": 39, "name": "Homer Tompson", "portrait_path": "https://cdn.thesimpsonsapi.com/500/character/1.webp" }, { "id": 2, "age": 39, "name": "Marge Simpson", "portrait_path": "https://cdn.thesimpsonsapi.com/500/character/2.webp" }
] CODE_BLOCK:
[ { "id": 1, "age": 39, "name": "Homer Tompson", "portrait_path": "https://cdn.thesimpsonsapi.com/500/character/1.webp" }, { "id": 2, "age": 39, "name": "Marge Simpson", "portrait_path": "https://cdn.thesimpsonsapi.com/500/character/2.webp" }
] COMMAND_BLOCK:
sudo apt install nlohmann-json3-dev COMMAND_BLOCK:
sudo apt install nlohmann-json3-dev COMMAND_BLOCK:
sudo apt install nlohmann-json3-dev COMMAND_BLOCK:
#include <iostream>
#include <fstream>
#include <string>
#include <regex>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <nlohmann/json.hpp> using json = nlohmann::json; // Cargar archivo JSON
json load_characters() { std::ifstream f("data.json"); json data; f >> data; return data;
} std::string make_json_response(const json& data, int status=200) { std::string body = data.dump(); return "HTTP/1.1 " + std::to_string(status) + " OK\r\n" "Content-Type: application/json\r\n" "Content-Length: " + std::to_string(body.size()) + "\r\n" "Connection: close\r\n\r\n" + body;
} int main() { int server = socket(AF_INET, SOCK_STREAM, 0); sockaddr_in addr{}; addr.sin_family = AF_INET; addr.sin_port = htons(7001); addr.sin_addr.s_addr = INADDR_ANY; bind(server, (sockaddr*)&addr, sizeof(addr)); listen(server, 10); std::cout << "Servidor corriendo en http://localhost:7001/characters\n"; while (true) { int client = accept(server, nullptr, nullptr); char buffer[4096] = {0}; read(client, buffer, sizeof(buffer)); std::string request(buffer); size_t s = request.find("GET "); size_t e = request.find(" HTTP/"); std::string path = request.substr(s + 4, e - (s + 4)); json data = load_characters(); // /characters if (path == "/characters") { auto res = make_json_response(data, 200); send(client, res.c_str(), res.size(), 0); close(client); continue; } // /characters/:id std::regex reg("^/characters/([0-9]+)$"); std::smatch match; if (std::regex_match(path, match, reg)) { int id = std::stoi(match[1]); json found = nullptr; for (auto& c : data) if (c["id"] == id) found = c; if (!found.is_null()) { auto res = make_json_response(found, 200); send(client, res.c_str(), res.size(), 0); } else { auto res = make_json_response({{"error","Character not found"}}, 404); send(client, res.c_str(), res.size(), 0); } close(client); continue; } // Ruta no encontrada json notfound = { {"error", "Route not found"}, {"url_list", "http://localhost:7001/characters"}, {"url_character", "http://localhost:7001/characters/1"} }; auto res = make_json_response(notfound, 404); send(client, res.c_str(), res.size(), 0); close(client); }
} COMMAND_BLOCK:
#include <iostream>
#include <fstream>
#include <string>
#include <regex>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <nlohmann/json.hpp> using json = nlohmann::json; // Cargar archivo JSON
json load_characters() { std::ifstream f("data.json"); json data; f >> data; return data;
} std::string make_json_response(const json& data, int status=200) { std::string body = data.dump(); return "HTTP/1.1 " + std::to_string(status) + " OK\r\n" "Content-Type: application/json\r\n" "Content-Length: " + std::to_string(body.size()) + "\r\n" "Connection: close\r\n\r\n" + body;
} int main() { int server = socket(AF_INET, SOCK_STREAM, 0); sockaddr_in addr{}; addr.sin_family = AF_INET; addr.sin_port = htons(7001); addr.sin_addr.s_addr = INADDR_ANY; bind(server, (sockaddr*)&addr, sizeof(addr)); listen(server, 10); std::cout << "Servidor corriendo en http://localhost:7001/characters\n"; while (true) { int client = accept(server, nullptr, nullptr); char buffer[4096] = {0}; read(client, buffer, sizeof(buffer)); std::string request(buffer); size_t s = request.find("GET "); size_t e = request.find(" HTTP/"); std::string path = request.substr(s + 4, e - (s + 4)); json data = load_characters(); // /characters if (path == "/characters") { auto res = make_json_response(data, 200); send(client, res.c_str(), res.size(), 0); close(client); continue; } // /characters/:id std::regex reg("^/characters/([0-9]+)$"); std::smatch match; if (std::regex_match(path, match, reg)) { int id = std::stoi(match[1]); json found = nullptr; for (auto& c : data) if (c["id"] == id) found = c; if (!found.is_null()) { auto res = make_json_response(found, 200); send(client, res.c_str(), res.size(), 0); } else { auto res = make_json_response({{"error","Character not found"}}, 404); send(client, res.c_str(), res.size(), 0); } close(client); continue; } // Ruta no encontrada json notfound = { {"error", "Route not found"}, {"url_list", "http://localhost:7001/characters"}, {"url_character", "http://localhost:7001/characters/1"} }; auto res = make_json_response(notfound, 404); send(client, res.c_str(), res.size(), 0); close(client); }
} COMMAND_BLOCK:
#include <iostream>
#include <fstream>
#include <string>
#include <regex>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <nlohmann/json.hpp> using json = nlohmann::json; // Cargar archivo JSON
json load_characters() { std::ifstream f("data.json"); json data; f >> data; return data;
} std::string make_json_response(const json& data, int status=200) { std::string body = data.dump(); return "HTTP/1.1 " + std::to_string(status) + " OK\r\n" "Content-Type: application/json\r\n" "Content-Length: " + std::to_string(body.size()) + "\r\n" "Connection: close\r\n\r\n" + body;
} int main() { int server = socket(AF_INET, SOCK_STREAM, 0); sockaddr_in addr{}; addr.sin_family = AF_INET; addr.sin_port = htons(7001); addr.sin_addr.s_addr = INADDR_ANY; bind(server, (sockaddr*)&addr, sizeof(addr)); listen(server, 10); std::cout << "Servidor corriendo en http://localhost:7001/characters\n"; while (true) { int client = accept(server, nullptr, nullptr); char buffer[4096] = {0}; read(client, buffer, sizeof(buffer)); std::string request(buffer); size_t s = request.find("GET "); size_t e = request.find(" HTTP/"); std::string path = request.substr(s + 4, e - (s + 4)); json data = load_characters(); // /characters if (path == "/characters") { auto res = make_json_response(data, 200); send(client, res.c_str(), res.size(), 0); close(client); continue; } // /characters/:id std::regex reg("^/characters/([0-9]+)$"); std::smatch match; if (std::regex_match(path, match, reg)) { int id = std::stoi(match[1]); json found = nullptr; for (auto& c : data) if (c["id"] == id) found = c; if (!found.is_null()) { auto res = make_json_response(found, 200); send(client, res.c_str(), res.size(), 0); } else { auto res = make_json_response({{"error","Character not found"}}, 404); send(client, res.c_str(), res.size(), 0); } close(client); continue; } // Ruta no encontrada json notfound = { {"error", "Route not found"}, {"url_list", "http://localhost:7001/characters"}, {"url_character", "http://localhost:7001/characters/1"} }; auto res = make_json_response(notfound, 404); send(client, res.c_str(), res.size(), 0); close(client); }
} CODE_BLOCK:
g++ api.cpp -o api -std=c++17
./api CODE_BLOCK:
g++ api.cpp -o api -std=c++17
./api CODE_BLOCK:
g++ api.cpp -o api -std=c++17
./api COMMAND_BLOCK:
# Instalar:
sudo apt install qtbase5-dev COMMAND_BLOCK:
# Instalar:
sudo apt install qtbase5-dev COMMAND_BLOCK:
# Instalar:
sudo apt install qtbase5-dev CODE_BLOCK:
#include <QApplication>
#include <QWidget>
#include <QLineEdit>
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel> int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget window; window.setWindowTitle("Calculadora Qt"); // Inputs QLineEdit *input1 = new QLineEdit(); QLineEdit *input2 = new QLineEdit(); QLabel *result = new QLabel("Resultado: "); input1->setPlaceholderText("Número 1"); input2->setPlaceholderText("Número 2"); // Buttons QPushButton *btnAdd = new QPushButton("+"); QPushButton *btnSub = new QPushButton("-"); QPushButton *btnMul = new QPushButton("*"); QPushButton *btnDiv = new QPushButton("/"); // Horizontal layout for buttons QHBoxLayout *buttonsLayout = new QHBoxLayout(); buttonsLayout->addWidget(btnAdd); buttonsLayout->addWidget(btnSub); buttonsLayout->addWidget(btnMul); buttonsLayout->addWidget(btnDiv); // Main layout QVBoxLayout *layout = new QVBoxLayout(); layout->addWidget(input1); layout->addWidget(input2); layout->addLayout(buttonsLayout); layout->addWidget(result); window.setLayout(layout); // Helper function to calculate auto calc = [&](char op) { double a = input1->text().toDouble(); double b = input2->text().toDouble(); double r = 0; switch (op) { case '+': r = a + b; break; case '-': r = a - b; break; case '*': r = a * b; break; case '/': r = (b != 0) ? a / b : 0; break; } result->setText("Resultado: " + QString::number(r)); }; // Connect buttons QObject::connect(btnAdd, &QPushButton::clicked, [&]() { calc('+'); }); QObject::connect(btnSub, &QPushButton::clicked, [&]() { calc('-'); }); QObject::connect(btnMul, &QPushButton::clicked, [&]() { calc('*'); }); QObject::connect(btnDiv, &QPushButton::clicked, [&]() { calc('/'); }); window.show(); return app.exec();
} CODE_BLOCK:
#include <QApplication>
#include <QWidget>
#include <QLineEdit>
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel> int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget window; window.setWindowTitle("Calculadora Qt"); // Inputs QLineEdit *input1 = new QLineEdit(); QLineEdit *input2 = new QLineEdit(); QLabel *result = new QLabel("Resultado: "); input1->setPlaceholderText("Número 1"); input2->setPlaceholderText("Número 2"); // Buttons QPushButton *btnAdd = new QPushButton("+"); QPushButton *btnSub = new QPushButton("-"); QPushButton *btnMul = new QPushButton("*"); QPushButton *btnDiv = new QPushButton("/"); // Horizontal layout for buttons QHBoxLayout *buttonsLayout = new QHBoxLayout(); buttonsLayout->addWidget(btnAdd); buttonsLayout->addWidget(btnSub); buttonsLayout->addWidget(btnMul); buttonsLayout->addWidget(btnDiv); // Main layout QVBoxLayout *layout = new QVBoxLayout(); layout->addWidget(input1); layout->addWidget(input2); layout->addLayout(buttonsLayout); layout->addWidget(result); window.setLayout(layout); // Helper function to calculate auto calc = [&](char op) { double a = input1->text().toDouble(); double b = input2->text().toDouble(); double r = 0; switch (op) { case '+': r = a + b; break; case '-': r = a - b; break; case '*': r = a * b; break; case '/': r = (b != 0) ? a / b : 0; break; } result->setText("Resultado: " + QString::number(r)); }; // Connect buttons QObject::connect(btnAdd, &QPushButton::clicked, [&]() { calc('+'); }); QObject::connect(btnSub, &QPushButton::clicked, [&]() { calc('-'); }); QObject::connect(btnMul, &QPushButton::clicked, [&]() { calc('*'); }); QObject::connect(btnDiv, &QPushButton::clicked, [&]() { calc('/'); }); window.show(); return app.exec();
} CODE_BLOCK:
#include <QApplication>
#include <QWidget>
#include <QLineEdit>
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel> int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget window; window.setWindowTitle("Calculadora Qt"); // Inputs QLineEdit *input1 = new QLineEdit(); QLineEdit *input2 = new QLineEdit(); QLabel *result = new QLabel("Resultado: "); input1->setPlaceholderText("Número 1"); input2->setPlaceholderText("Número 2"); // Buttons QPushButton *btnAdd = new QPushButton("+"); QPushButton *btnSub = new QPushButton("-"); QPushButton *btnMul = new QPushButton("*"); QPushButton *btnDiv = new QPushButton("/"); // Horizontal layout for buttons QHBoxLayout *buttonsLayout = new QHBoxLayout(); buttonsLayout->addWidget(btnAdd); buttonsLayout->addWidget(btnSub); buttonsLayout->addWidget(btnMul); buttonsLayout->addWidget(btnDiv); // Main layout QVBoxLayout *layout = new QVBoxLayout(); layout->addWidget(input1); layout->addWidget(input2); layout->addLayout(buttonsLayout); layout->addWidget(result); window.setLayout(layout); // Helper function to calculate auto calc = [&](char op) { double a = input1->text().toDouble(); double b = input2->text().toDouble(); double r = 0; switch (op) { case '+': r = a + b; break; case '-': r = a - b; break; case '*': r = a * b; break; case '/': r = (b != 0) ? a / b : 0; break; } result->setText("Resultado: " + QString::number(r)); }; // Connect buttons QObject::connect(btnAdd, &QPushButton::clicked, [&]() { calc('+'); }); QObject::connect(btnSub, &QPushButton::clicked, [&]() { calc('-'); }); QObject::connect(btnMul, &QPushButton::clicked, [&]() { calc('*'); }); QObject::connect(btnDiv, &QPushButton::clicked, [&]() { calc('/'); }); window.show(); return app.exec();
} CODE_BLOCK:
g++ qt-calc.cpp -o app-qt-calc -fPIC $(pkg-config --cflags --libs Qt5Widgets) ./app-qt-calc CODE_BLOCK:
g++ qt-calc.cpp -o app-qt-calc -fPIC $(pkg-config --cflags --libs Qt5Widgets) ./app-qt-calc CODE_BLOCK:
g++ qt-calc.cpp -o app-qt-calc -fPIC $(pkg-config --cflags --libs Qt5Widgets) ./app-qt-calc - C++ - Referencia en CPPReference
- C++ - En DevDocs.io - Sin Framework (sockets POSIX) — Minimalista, simple, nativo.
- Crow — Inspirado en Flask, muy fácil de usar.
- Boost.Beast — Rápido y moderno para HTTP/WebSocket.
- CppRestSDK — Completo, estilo Django/Express. - apt (en Ubuntu) - Lee datos desde un archivo data.json
- Expone dos endpoints: - Lista de personajes en /characters
- Datos por ID en /characters/:id - Crea una pequeña calculadora gráfica usando Qt5.
- Toma dos números como entrada.
- Proporciona cuatro botones: sumar, restar, multiplicar, dividir.
- Muestra el resultado dentro de la ventana.
- Compila usando Qt5Widgets en Ubuntu.