/* //enumerate사용법 fn main() { let s = String::from("hello"); return_char(&s); } fn return_char(s: &String) -> usize { let bytes = s.as_bytes(); enumerate()함수는 튜플을 반환한다. for (i,&item) in bytes.iter().enumerate(){ println!("i : {}, item : {}",i,item); if item == b' '{ return i; } } s.len() } */ /* //문자열 슬라이스 fn main() { let s = String::from("hello world"); let hello = &s[0..5]; let world = &s[6..1..
//컴파일 시 크기를 알 수 없는(동적할당)을 사용하는 변수의 데이터 대입법 /*fn main() { let s1 = String::from("hello"); let s2 = s1; //이렇게 하면 s1은 사용할 수 없을것이다 그 이유는 copy를 한게아니라 //move를 한것이기 때문이다. println!("{}, world!", s1); println!("{}, world!",s2); }*/ /* //같이 사용하고 싶다면 클론 함수를 사용하여 복사를 할 수 있다. fn main() { let s1 = String::from("hello"); let s2 = s1.clone(); println!("s1 = {}, s2 = {}",s1,s2); } */ /* //스택 전용 데이터 : 복사(copy) fn..
use std::io; fn main() { println!("피보나치 나열 프로그램"); let mut s_loop = String::new(); while true{ println!("몇번 반복하시겠습니까? : "); s_loop.clear(); match io::stdin().read_line(&mut s_loop) { Ok(_) => {} Err(error) => { println!("입력중 에러가 발생하였습니다. : {}",error); continue; } }; let mut n_loop: i32 = match s_loop.trim().parse(){ Ok(num) => num, Err(_) =>{ println!("입력한 문자열을 정수로 변환중에 에러가 발생하였습니다."); continue ..
use std::io; fn main() { println!("=========섭씨 화씨 변환 프로그램==========="); //ctrl + c를 입력할때까지 무한 반복 while true{ println!("기호화 함께 온도를 입력해주세요(ex : 32f, 32c"); //사용자로부터 온도를 입력받음 let mut s_temper = String::new(); match io::stdin().read_line(&mut s_temper){ Ok(_size) => {} Err(_) => { println!("알수없는 이유로 입력에서 에러가 발생하였습니다. 처음으로 돌아갑니다."); continue; } } //rans_temper로 부터 변환된 문자열을 받고 출력 let result_temper = t..
/* //if 표현식 fn main() { let number = 3; if number < 5{ //조건은 bool타입으로만 실행됨 println!("조건이 일치합니다."); } else{ println!("조건이 일치하지 않습니다."); } } */ /* //let구문에서 if표현식 사용 fn main() { let condition = true; let number = if condition{ //표현식의 데이터타입이 다르다면 에러가 난다. 5 } else{ 6 }; println!("number의 값은 {}입니다.",number); } */ /* //루프에서 값 리턴하기 fn main() { let mut counter = 0; let result = loop{ counter+=1; if coun..
/* //함수 사용 fn main() { println!("Hello, world!"); another_function(); } fn another_function() { println!("또 다른 함수"); } */ /* //함수 매개 변수 fn main() { another_function(5); another_function2(1,5); } fn another_function(x: u32) { println!("x : {}",x); } fn another_function2(x: i32, y:u32) { println!("x : {}\r\ny : {}",x,y); } */ /* //표현식과 구문 차이 fn main() { let x = {//구문 let y=3; y+1//표현식(표현식에는 ';'를 사..
/////////////////스칼라 타입 /* //매크로 const MAX_POINTS: u32 = 100_1000; fn main() { //let만 사용하면 불변이며 mut을 추가하면 가변이 된다. let mut x = 5; println!("x의 값 : {}",x); x = 6; println!("x의 값 : {}",x); println!("MAX_POINTS의 값 : {}", MAX_POINTS); }*/ //변수 가리기 /*fn main() { //똑같은 변수 이름을 선언하면 그 전에 선언된 변수는 가려진다. let x = 5; let x = x + 1; let x = x * 2; println!("x의 값 : {}",x); }*/ /* //let과 let mut의 차이 fn main() { ..
use std::io; use rand::Rng; use std::cmp::Ordering; fn main() { //문자를 출력한다. println!("숫자 맞추기 게임!!!!"); println!("숫자를 입력해주세요 : "); //난수를 얻는다. let rand_number = rand::thread_rng().gen_range(1,101); //반복한다. loop{ //let은 변수를 선언할 때 사용하며 기본적으로는 불변적이지만 앞에 mut을 붙이면 가변적으로 변한다. let mut input_number = String::new(); //사용자로부터 문자,문자열을 입력받는다. io::stdin().read_line(&mut input_number).expect("오류입니다."); //사용자로부터..
쉬고왔는데도 몸이 좋아지기는 커녕 먹는 약만 늘어났네 ;;; 하던 알바도 그만둬야하나....
//menu.h #ifndef MENU_H #define MENU_H #include #include #include //메인 메뉴의 추상클래스 class MainMenu { public: //메뉴 이름 virtual QString& GetName() = 0; //메뉴 가격 virtual double Cost() const = 0; }; //돈카츠 class Tonkatsu : public MainMenu { private: QString name; public: Tonkatsu() :name("Tonkatsu"){} virtual QString& GetName() { return name; } virtual double Cost() const { return 111.11; } }; //우동 class ..
//observer.h #ifndef OBSERVER_H #define OBSERVER_H #include #include #include #include #include #include #include #include class ProcessData; class Observer { public: virtual ~Observer(){} virtual void Update(QVector* ProcessName,QVector* ProcessId)=0; }; class DisplayData { public: virtual ~DisplayData(){} virtual void Display(QWidget* widget)=0; }; class Subject { public: virtual ~Subject(){} ..
//fly.h #ifndef ORDER_H #define ORDER_H #include class FlyBehavior { public: FlyBehavior(){} ~FlyBehavior(){} virtual QSharedPointer fly() = 0; }; class RocketFly : public FlyBehavior { private: QSharedPointerlb; public: RocketFly(){} ~RocketFly(){} virtual QSharedPointer fly() { lb.reset(new QLabel("로켓엔진으로 난다!")); return lb; } }; class WingFly : public FlyBehavior { private: QSharedPointerlb; p..
왜 이건 스레드가 아니냐고? 그냥 한번 스레드 적용안하고만들어봤는데 세상 편하더라 와...... 서버와 연결된 모습 닉네임이나 UID가 없으니까 누가 무슨메시지 친지를 모르겠더라고 그래서 나아아~중에 추가해봐야지 서버가 꺼지면 연결된 클라 다 꺼짐 //input_widget.h #ifndef INPUT_WIDGET_H #define INPUT_WIDGET_H #include #include #include #include #include #include #include #include #include #include #include class InputDialog : public QDialog { Q_OBJECT private: // //GUI 버튼 // //IP 입력 부분 QSharedPointerip..
서버 기능 : 클라로부터 받은 데이터를 서버의 로그에 올려주고 서버와 연결된 모든 클라이언트에 다시 뿌린다.(그냥 말만 번지르르한 평범하면서도 모자란 서버) //recv_thread.h #ifndef RECV_THREAD_H #define RECV_THREAD_H #include #include #include #include #include #include #include #include #include #include #include #include #include #include class RecvThread : public QThread { Q_OBJECT private: //리스트 모델 QSharedPointerlist_model; //들어온 소켓을 모아놓음 //QSetsocket_list; Q..
서버 기능 : 클라이언트로부터 데이터를 받고 받은 데이터를 서버 리스트뷰에 올려주는 거밖에 못해 //widget.cpp #include "widget.h" Widget::Widget(QWidget *parent) : QWidget(parent) { //GUI 부분 setFixedSize(500,700); list_model = QSharedPointer (new QStringListModel(this)); list_view = QSharedPointer (new QListView); list_view->setModel(list_model.get()); layout = QSharedPointer (new QVBoxLayout(this)); layout->addWidget(list_view.get()); s..
새창을 띄우는 방법을 모르면은 먼저 이 글을 읽고 오는게 좋을꺼야 2021-01-22-start.tistory.com/101 모달방식, 모달리스 방식 새창 띄우기 새창을 띄우는 방법 없나 찾아보는 도중에 모달 방식과 모달리스방식이 두가지 방식의 새 창 띄우기가 있다고 하더라 그래서 찾아와봤어 //Modaless.h #ifndef MODALESS_H #define MODALESS_H #include #include c.. 2021-01-22-start.tistory.com 미안하다 어휘능력 부족으로 설명을 못하겠다....... 이걸 어떻게 설명을 해야할지 몰라서 일단 예제에 주석이랑 다 달아놨어 전체적인 흐름은 메인 위젯에서 "클릭시 데이터 전달" 이라는 QPushButton을 클릭 시 새로 띄어진 서브 ..
새창을 띄우는 방법 없나 찾아보는 도중에 모달 방식과 모달리스방식이 두가지 방식의 새 창 띄우기가 있다고 하더라 그래서 찾아와봤어 //Modaless.h #ifndef MODALESS_H #define MODALESS_H #include #include class Modaless : public QDialogshow(); //모달리스 방식 ///////////////////////////////////////// } Widget::~Widget() { } 모달방식은 새로 띄어진 창이 켜져있는 한 부모를 제어할 수 없는 방식이야 꼭 중요한 메시지를 전할 때 좋을거같더라 모달리스 방식은 그런거 상관없이 부모든 새로 띄어진 창이든 마음대로 제어할 수 있는거야
만약 QMutex자체를 어떻게 사용하는지 모르면은 링크를 걸어놓은 글을 먼저 보고오는것을 추천해 2021-01-22-start.tistory.com/99 안전하게 QMutex 쓰기 스래드를 사용하는데에 동기화를 하는것은 매우 중요하다 안그러면 공유자원을 제대로 쓰지못한다. 그래서 나온것이 동기화이다. 동기화 기법중에 하나인 mutex를 써보자 #include #include #include #in 2021-01-22-start.tistory.com #include #include #include #include #include static int num_data; static QMutex mutex; static QWaitCondition wait_condition; class MyThread1 : pu..
스래드를 사용하는데에 동기화를 하는것은 매우 중요하다 안그러면 공유자원을 제대로 쓰지못한다. 그래서 나온것이 동기화이다. 동기화 기법중에 하나인 mutex를 써보자 #include #include #include #include static int num_data; static QMutex mutex; class MyThread1 : public QThread { Q_OBJECT private: void run() override { for(int i=0;i
#include "widget.h" Widget::Widget(QWidget *parent) : QWidget(parent) { host_address = QSharedPointer (new QHostAddress(QHostAddress::LocalHost)); //IP 부분 생성; ip_label = QSharedPointer (new QLabel("IP 입력 : ")); ip_edit = QSharedPointer (new QLineEdit(host_address->toString())); ip_layout = QSharedPointer (new QHBoxLayout); ip_layout->addWidget(ip_label.get()); ip_layout->addWidget(ip_edit.get())..
#include "widget.h" Widget::Widget(QWidget *parent) : QWidget(parent) { //아이피 포트 출력해주는 라벨 ip_port_lb = QSharedPointer (new QLabel); //리스트 뷰 설정 list_model = QSharedPointer (new QStringListModel); list_view = QSharedPointer (new QListView); list_view->setModel(list_model.get()); box_layout = QSharedPointer (new QVBoxLayout); box_layout->addWidget(list_view.get()); view_box = QSharedPointer (new QG..
어떤 분이 어제 이걸로 엄청 고생하시길래 알려드렸다. 혹시나 다른 사람들도 이걸로 고생하는사람있으면 이거 참고하면서 하길 바래 #include #include using namespace std; typedef struct node { string name; int id; float salary; node* next_node; }NODE, * PNODE; /** @brief : 노드를 추가해 주는 함수 @details : VOID @arg : INNODE&header: 노드를 더 추가할 노드헤더를 넣는다. INconst char* name: 이름 IN const int&id:아이디 IN const float& salary: salary @return : VOID */ void Add_Node(NODE& ..
#include "widget.h" Widget::Widget(QWidget *parent) : QWidget(parent) { //타이머 timer = QSharedPointer (new QTimer(this)); //버튼 생성 및 STOP 버튼 비활성화 start_btn = QSharedPointer (new QPushButton("타이머 시작",this)); stop_btn = QSharedPointer (new QPushButton("타이머 중지",this)); stop_btn->setDisabled(true); btn_layout = QSharedPointer (new QHBoxLayout); btn_layout->addWidget(start_btn.get()); btn_layout->addWi..
#include "widget.h" Widget::Widget(QWidget *parent) : QWidget(parent) { //버튼 생성 open_btn = QSharedPointer (new QPushButton("File Open",this)); write_btn = QSharedPointer (new QPushButton("File Write",this)); close_btn = QSharedPointer (new QPushButton("File Close",this)); //세로 레이어 생성 및 레이어에 버튼 추가 layout = QSharedPointer (new QVBoxLayout(this)); layout->addWidget(open_btn.get()); layout->addWidge..
#include "widget.h" Widget::Widget(QWidget *parent) : QWidget(parent) { QString btn_str[5] = {"One","Two","Three","four","Five"}; grid_layout = QSharedPointer (new QGridLayout(this)); for(int i=0;iaddWidget(gbtn[0].get(),0,0); //컴퓨터에선 0이 첫번째이다. grid_layout->addWidget(gbtn[1].get(),0,1); //1번재 줄 2번째 칸 grid_layout->addWidget(gbtn[2].get(),1,0,1,2); //2번째 줄 1,2,3칸 차지 grid_layout->addWidget(gbtn[3]...
#include "widget.h" Widget::Widget(QWidget *parent) : QWidget(parent) { tab = QSharedPointer(new QTabBar(this)); tab->addTab("Browser"); //탭이름 tab->addTab("User"); //탭이름 tab->addTab("Application"); //탭이름 tab->setShape(QTabBar::RoundedNorth);//누르면 탭이 튀어 나오는 방향 tab->setGeometry(20,20,300,250); connect(tab.get(),SIGNAL(currentChanged(int)),//탭 바꾸면 currentTab함수 호출 this, SLOT(currentTab(int))); } voi..
#include "widget.h" Widget::Widget(QWidget *parent) : QWidget(parent) { setFixedSize(500,500); qde1=QSharedPointer (new QDateTimeEdit(QDateTime::currentDateTime(),this)); //DateTimeEdit을 //현재 시각을 넣어서 생성 qde1->setDisplayFormat("yyyy-MM-dd hh:mm:ss:zzz"); qde1->setGeometry(10,30,250,50);//x,w,width,height qde[0] = QSharedPointer (new QDateTimeEdit(QDateTime::currentDateTime(),this)); qde[0]->setMi..
#include "widget.h" Widget::Widget(QWidget *parent) : QWidget(parent) { int xpos=30; for(int i=0;isetRange(0,100); //dial의 값 범위 설정 dial[i]->setGeometry(xpos,30,100,100); } dial[0]->setNotchesVisible(true); //다이얼에 눈금표시할것인가 안할것인가 connect(dial[0].get(),&QDial::valueChanged,this,&Widget::Changed_Data); //QDial의 값이 바뀔때마다 //Changed_Data함수를 호출함 } void Widget::Changed_Data() { qDebug("QDial 1 value : %d..