在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+是最流行的选择,它们都有强大的社区支持和丰富的文档资源。