在Linux環境下進行C++圖形界面開發,你可以選擇多種庫和框架。以下是一些流行的選擇:
Qt:
sudo apt-get install qt5-default
#include <QApplication>
#include <QMainWindow>
#include <QPushButton>
#include <QMessageBox>
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QMainWindow window;
QPushButton *button = new QPushButton("Click Me", &window);
button->setGeometry(100, 100, 100, 30);
QObject::connect(button, SIGNAL(clicked()), &window, SLOT(close()));
window.show();
return app.exec();
}
GTK+:
sudo apt-get install libgtkmm-3-dev
#include <gtkmm.h>
int main(int argc, char *argv[]) {
auto app = Gtk::Application::create(argc, argv, "org.gtkmm.example");
Gtk::Window window;
window.set_title("Hello, GTKmm!");
window.set_default_size(200, 200);
return app->run(window);
}
wxWidgets:
sudo apt-get install libwxgtk3.0-dev
#include <wx/wx.h>
class MyApp : public wxApp {
public:
virtual bool OnInit() {
MyFrame *frame = new MyFrame("wxWidgets Example");
frame->Show(true);
return true;
}
};
class MyFrame : public wxFrame {
public:
MyFrame(const wxString& title) : wxFrame(nullptr, wxID_ANY, title) {}
};
IMPLEMENT_APP(MyApp)
FLTK:
sudo apt-get install libfltk1.3-dev
X11:
選擇哪個庫取決于你的具體需求、偏好以及項目的復雜性。Qt和GTK+是最流行的選擇,它們都有強大的社區支持和豐富的文檔資源。