×ðÁú¿­Ê±

LinuxÏÂʹÓÃQt¿ª·¢Í¼ÐνçÃæÓ¦ÓõĻù±¾ÉèÖÃÖ¸ÄÏ

linuxÏÂʹÓÃqt¿ª·¢Í¼ÐνçÃæÓ¦ÓõĻù±¾ÉèÖÃÖ¸ÄÏ

Ò»¡¢Ð¡Ðò

QtÊÇÒ»Ì׿çƽ̨µÄC++¿â £¬ËüÌṩÁ˸»ºñµÄͼÐνçÃ濪·¢×é¼þ £¬ÒÔ¼°Ðí¶àÆäËûµÄ¹¦Ð§Ä£¿é £¬ÊÊÓÃÓÚ¿ª·¢¿çƽ̨µÄͼÐνçÃæÓ¦ÓóÌÐò¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚLinuxϵͳϾÙÐÐQt¿ª·¢ £¬²¢¸ø³öһЩ»ù±¾µÄÉèÖÃÖ¸ÄϺʹúÂëʾÀý¡£

¶þ¡¢×°ÖÃQt¿ª·¢ÇéÐÎ

ÏÂÔØQt

ÔÚQt¹Ù·½ÍøÕ¾ÉÏ (http://www.qt.io/) ÏÂÔغÏÊʵÄQt¿ª·¢Õ߰档ѡÔñºÏÊʵİ汾ºÍ×°Öðü £¬²¢Æ¾Ö¤¹Ù·½ÎĵµµÄÖ¸Òý¾ÙÐÐ×°Öá£×°ÖÃÀú³ÌÖпÉÒÔÑ¡Ôñ×°ÖÃËùÐèµÄ×é¼þºÍʾÀý´úÂë¡£

×°ÖñàÒëÆ÷ºÍ¹¹½¨¹¤¾ß

Qt¹Ù·½ÍƼöʹÓÃGCC×÷ΪC++±àÒëÆ÷¡£È·±£×°ÖÃÁ˺ÏÊÊ°æ±¾µÄGCC £¬ÔËÐÐÒÔÏÂÏÂÁî¾ÙÐмì²é£º

$ gcc --version

µÇ¼ºó¸´ÖÆ

ÁíÍâ £¬ÎªÁ˱àÒëºÍ¹¹½¨QtÓ¦Óà £¬»¹ÐèҪװÖÃCMakeºÍMake¹¤¾ß¡£ÔËÐÐÒÔÏÂÏÂÁî¾ÙÐÐ×°Öãº

$ sudo apt-get install cmake make

µÇ¼ºó¸´ÖÆ

ÉèÖÃQt Creator

Qt¿ª·¢³£Óõļ¯³É¿ª·¢ÇéÐÎÊÇQt Creator¡£×°ÖÃÍêQtºó £¬¿ÉÒÔÖ±½ÓÔÚÓ¦ÓóÌÐò²Ëµ¥ÖÐÕÒµ½Qt Creator £¬Æô¶¯Ëü¼´¿É¡£

ÔÚQt CreatorÖÐ £¬µã»÷ “¹¤¾ß” -> “Ñ¡Ïî” -> “¹¹½¨ºÍÔËÐД -> “¹¤¾ßÁ´” £¬È·±£Ñ¡ÖÐÁ˺ÏÊʵıàÒëÆ÷¡£ÔÚ “¹¹½¨Ì×¼þ” Ñ¡ÏÖÐ £¬Ñ¡ÔñºÏÊʵÄQt°æ±¾¡£

Èý¡¢½¨ÉèÒ»¸ö¼òÆÓµÄQtÓ¦ÓÃ

н¨QtÏîÄ¿

ÔÚQt CreatorÖÐ £¬µã»÷ “Îļþ” -> “н¨Îļþ»òÏîÄ¿” -> “Ó¦ÓÔ £¬Ñ¡Ôñ “Qt WidgetsÓ¦ÓÔ¡£ÌîдÏîÄ¿Ãû³ÆºÍ·¾¶ £¬µã»÷ “ÏÂÒ»²½”¡£

±àд´úÂë

ÔÚн¨µÄÏîÄ¿ÖÐ £¬·­¿ª “mainwindow.h” Îļþ £¬±àдÈçÏ´úÂ룺

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

class MainWindow : public QMainWindow
{
 Q_OBJECT

public:
 MainWindow(QWidget *parent = nullptr);
 ~MainWindow();
};

#endif // MAINWINDOW_H

µÇ¼ºó¸´ÖÆ

È»ºó £¬·­¿ª “mainwindow.cpp” Îļþ £¬±àдÈçÏ´úÂ룺

#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
}

MainWindow::~MainWindow()
{
}

µÇ¼ºó¸´ÖÆ

±àÒëºÍÔËÐÐÓ¦ÓÃ

µã»÷ “¹¹½¨” -> “¹¹½¨ÏîÄ¿” £¬ÆÚ´ý±àÒëÍê³É¡£È»ºóµã»÷ “ÔËÐД -> “ÔËÐД £¬¼´¿ÉÆô¶¯Ó¦ÓóÌÐò¡£

ËÄ¡¢Ìí¼Ó½çÃæ×é¼þ

ÔÚQtÓ¦ÓÃÖÐ £¬¿ÉÒÔͨ¹ý½çÃæÉè¼ÆÆ÷À´Ìí¼ÓÖÖÖÖ×é¼þ¡£µã»÷ “ÏîÄ¿” -> “Ìí¼ÓД -> “Qt” £¬Ñ¡ÔñÐèÒªÌí¼ÓµÄ×é¼þ¡£

ÀýÈç £¬ÒªÌí¼ÓÒ»¸ö°´Å¥ £¬¿ÉÒÔÑ¡Ôñ “Qt Widgets” -> “PushButton” £¬È»ºóÍÏקµ½´°¿ÚÖм´¿É¡£

Îå¡¢Ìí¼ÓÊÂÎñ´¦Öóͷ£

ÔÚmainwindow.hÎļþÖÐ £¬Ìí¼ÓÒ»¸ö²Ûº¯Êý£º

private slots:
 void onButtonClicked();

µÇ¼ºó¸´ÖÆ

ÔÚmainwindow.cppÎļþÖÐ £¬ÊµÏָòۺ¯Êý£º

void MainWindow::onButtonClicked()
{
 // ´¦Öóͷ£°´Å¥µã»÷ÊÂÎñ
}

µÇ¼ºó¸´ÖÆ

ÔÚmainwindow.cppµÄ½á¹¹º¯ÊýÖÐ £¬ÅþÁ¬°´Å¥µÄµã»÷ÐźÅÓë²Ûº¯Êý£º

MainWindow::MainWindow(QWidget *parent)
 : QMainWindow(parent)
{
 QPushButton *button = new QPushButton("Click Me", this);
 connect(button, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
}

µÇ¼ºó¸´ÖÆ

Áù¡¢×ܽá

±¾ÎÄÏÈÈÝÁËÔÚLinuxÏÂÉèÖÃQt¿ª·¢ÇéÐεĻù±¾°ì·¨ £¬²¢¸ø³öÁËÒ»¸ö½¨Éè¼òÆÓQtÓ¦ÓõÄʾÀý¡£Í¨¹ýѧϰºÍʵ¼ù £¬½øÒ»²½ÕÆÎÕQtµÄ¿ª·¢¼¼ÇɺÍÓ¦Óá£

¸½Â¼£º

ÍêÕûʾÀý´úÂëÇë²Î¿¼ÒÔÏÂÁ´½Ó£º[GitHub¿ÍÕ»](https://github.com/example/qt-basic-configuration)

£¨×¢£º¸ÃÎÄÕÂΪÐéÄâÖúÊÖ×Ô¶¯ÌìÉú £¬½ö¹©²Î¿¼¡££©

ÒÔÉϾÍÊÇLinuxÏÂʹÓÃQt¿ª·¢Í¼ÐνçÃæÓ¦ÓõĻù±¾ÉèÖÃÖ¸ÄϵÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±ÊµÊ±ÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
¡¾ÍøÕ¾µØͼ¡¿¡¾sitemap¡¿