Exemple #1
0
    // Handle the returnPressed() signal on our textline entry box.
    private void gotReturnPressed()
    {
        // Here is an example of how to use a custom C# event.
        // This function gets called by Qt's signal mechanism;
        // in response we pull the text string out of the textline,
        // clear the textline, and forward the string to a C# event.
        //
        // Note that forwarding the event is the LAST thing we do:
        // it is good practice to do this whenever possible,
        // because it avoids the possibility of subtle bugs
        // that might occur if the event handler ends up
        // calling back into this class recursively.
        //
        // Note also that we make a local copy of the MessageHandler
        // BEFORE we actually test it for null and call it.
        // This is good practice in case of multithreaded access,
        // as the event might change between the test and the call.
        String msg = textline.text();           // Get a copy of the string

        textline.clear();                       // Clear the textbox
        MessageHandler h = messageEntered;

        if (h != null)                          // Forward it as a C# event,
        {
            h(this, msg);                       // only if there is a handler.
        }
        else
        {
            //Console.WriteLine("Message entered: " + msg);
            addMessage("myself", msg);
            // Pass message from GUI to net class
            netCpy.msgFromGui(msg);
        }
    }