Small toys - temperature collection project (6)

After successfully entering the main interface, I only see a button, a division of an area, and nothing else. In fact, I want to add some beautiful pictures next to it, and it will disappear after entering the communication, but. . . become lazy.

Well, after we clicked the only button, we entered a dialog box to select the ip address and port number, there may be some bugs, because I just clicked it and set it up, and did not consider other situations. take the appropriate action.

In the dialog box of this setting, what I want to achieve is to display the corresponding information (ip address, port number, local ip, etc.) on the main interface after clicking ok, or some buttons, and so on. So, how can this be achieved? The dialog box is placed in the dialog class. I am thinking that if the coupling between classes is reduced, it is of course impossible to reduce it to 0. After all, you still need to call these functions in the main interface, so I will declare the class object pointer in this class. , If I wanted to declare the pointer before, it was applied in the heap, and it was deleted manually. The life cycle is longer. If it is declared in the stack, the declaration cycle is shorter, but after reading the pIpml method, it seems that there are many advantages. In the widget's constructor new, in the destructor delete, it seems that I define a friend function to delete the pointer defined in the deletedialog class, I don't remember why I want to do this. . . . Is it that when the main interface is destructed, delete will not delete all the things it contains?

Shouldn't it be necessary?

Well, to implement it, I use a bool type, return true when I click ok, and judge in the tcp/client slot function

if (!socket_dialog->dia_tcp_client())

is similar to the login interface, and return true is Display the rest of the interface.


In the following code, it should be noted that, for example, QPushButton btn = new QPushButton (parent window); I want to add it to a groupBox, but I didn't pay much attention to it at first. I wrote this, which means widget as the parent. Window, and groupBox is also this when new, that is, groupBox and btn are at the same level, whoever puts it later will cover whoever, and my groupBox will be covered on btn, the result is that my button cannot be clicked Well, this detail has also made me fiddle with it for a long time. requires attention.

There are also some that I really can't figure out. I just define its existence first, but setHidden(true) makes it not displayed first, but it has already taken up space, and I have not thought of a better way to do it. More convenient control, new method after I click to enter, occupying space.

The connection button really realizes the construction of the communication "circuit". There is nothing to say about this.

QDialog *dia;
dialog::dialog(QWidget *parent)

{

    dia = new QDialog(parent);

}

//friend function
void free_dialog(dialog *d)
{
    delete d->dia;
}

Widget::~Widget()
{
    free_socket(ctn); //Friend function releases socket
    free_dialog(socket_dialog); //friend function recycling dialog_socket

}
//connection *ctn; //tcp connection

//dialog *socket_dialog;  //在widget类中声明了这两个类对象


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325774741&siteId=291194637