Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Return a value from a QWidget
Forum Updated to NodeBB v4.3 + New Features

Return a value from a QWidget

Scheduled Pinned Locked Moved General and Desktop
8 Posts 5 Posters 4.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bitman
    wrote on last edited by
    #1

    Hello everybody,

    I'm a beginner with Qt and I can't find a solution to my problem.

    I want to have a login window, the user would then enter its login and password, and then, the main window will open according to the login information. (it can be a normal user, a super user, or wrong credentials)

    I don't want to use a QDialog for the login window, because I already have a class that implements the design of my software (title bar, logo and so on), so I would like to inherit from my own class, which itself inherit from QWidget, so that this class will open, and then wait for the user to enter its login informations.

    I already implemented the design of this window but I don't know how to block until the user puts his information. Moreover, I really want a return value, something like the exec() function of the QDialog. I looked at its implementation, but I can't understand it, and I guess something easier is possible.

    Thank you!

    1 Reply Last reply
    0
    • A Offline
      A Offline
      adolby
      wrote on last edited by
      #2

      It sounds like you're on the right track. Using QDialog::exec will start a modal dialog, which will block input to other windows in your application until the user enters input. Your QDialog instance could send a signal to a class that will verify credentials and return a value via signal that will allow the QDialog to determine whether it can be be accepted and close. The credential checking class can then signal the rest of your application to allow what features you want user types to have. If you post some code samples, people can help you more with your architecting process.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Bitman
        wrote on last edited by
        #3

        Thanks for your message.
        However, my point is that I don't want to use QDialog, but my own class instead, which inherits from QWidget.
        Therefore I need to implement the exec() function for that class.

        Let's say I have a class MyQWidget that inherits from QWidget. I want to do something like that:

        @MyQWidget qw;
        int m = qw.exec();

        if (m == 0) blablabla...@

        1 Reply Last reply
        0
        • _ Offline
          _ Offline
          _patrick_
          wrote on last edited by
          #4

          Why not inheriting from QDialog, or adding the inherited QWidget to a QDialog.

          1 Reply Last reply
          0
          • B Offline
            B Offline
            Bitman
            wrote on last edited by
            #5

            My example was wrong, but correct in my first post.
            I have a class that implements the design of my software, let's call it myWindow.
            This class inherits from QWidget.

            To create my login window, I want to inherit from myWindow, therefore I can't inherit from QDialog.

            Adding "myWindow" inside a QDialog seems to be a good solution, however I didn't find a good way to do this, as myWindow redefine everything including the title bar, I end up with two title bar....

            1 Reply Last reply
            0
            • M Offline
              M Offline
              msue
              wrote on last edited by
              #6

              Sorry to say that, but either you use the QDialog class (using your verification logic etc. of MyWindow) which will prove easier than you might think now or you end up re-inventing QDialog again.

              1 Reply Last reply
              0
              • B Offline
                B Offline
                Bitman
                wrote on last edited by
                #7

                But can I have my own design when using QDialog ?
                QDialog already has a title bar with the close button etc(with the Windows design), MyWindow has this bar too with my own design, so I end up with two title bars.
                Is it possible to remove everything in the QDialog?

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  Chrisw01
                  wrote on last edited by
                  #8

                  Hi,

                  For a QDialog try using this.

                  @
                  dialog->setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);
                  @

                  That should remove the title bar and all the buttons, in theory. If you insist on using your own format, you can use

                  @
                  this->setDisabled(true);
                  @

                  before you execute your custom dialog, just remember to use

                  @
                  this->setDisabled(false);
                  @

                  when your dialog is done or else your code will not process anymore events. As for returning values you may have to create a signal to send the information from your custom dialog.

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved