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. Beginners : how to input parameter to a widget
Forum Updated to NodeBB v4.3 + New Features

Beginners : how to input parameter to a widget

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 5.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.
  • S Offline
    S Offline
    SherifOmran
    wrote on last edited by
    #1

    Hi guys I want to create a widget and send parameter input_filename from main to it but i don't know how

    @
    #include <QtGui/QApplication>
    #include "widget.h"

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    Widget w;

    return a.exec&#40;&#41;;
    

    }
    @

    @
    Widget::Widget(QWidget *parent, QString input_filename = "setting.dB") :
    QWidget(parent)
    {
    }
    @

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Just pass your input into Widget's Constructor (this is C++ knowledge, not Qt knowledge)

      @
      // In Qt convention, we put 'parent' last so that it can always accept a default value (0)
      Widget::Widget(QString input_filename = "setting.dB", QWidget *parent = 0) :
      QWidget(parent)
      {
      }

      int main(int argc, char *argv[])
      {
      QApplication a(argc, argv);

      // Default input ("setting.dB"), no parent (null pointer)
      Widget w1();
      
      // Custom input ("my_input.dB"), no parent (null pointer)
      Widget w2("my_input.dB");
      
      // Custom input ("my_input.dB"), custom parent (pointer to other widget)
      QWidget *other_widget = /* Create other widget */
      Widget w3("my_input.dB", other_widget);
      
      
      // Show all three widgets
      w1.show();
      w2.show();
      w3.show();
      
      return a.exec&#40;&#41;;
      

      }
      @

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SherifOmran
        wrote on last edited by
        #3

        Is it possible to return a value after it the widget ends?

        something like
        QString path="xxxx";
        return path;

        should I call it this way
        QString v;
        v=Widget w("file1");

        thanks in advance

        1 Reply Last reply
        0
        • A Offline
          A Offline
          AcerExtensa
          wrote on last edited by
          #4

          [quote author="SherifOmran" date="1346316853"]Is it possible to return a value after it the widget ends?

          something like
          QString path="xxxx";
          return path;

          should I call it this way
          QString v;
          v=Widget w("file1");

          thanks in advance[/quote]

          No, constructors didn't have return type...
          Using constructor for expensive calculations is always bad idea....

          Use constructor for initializations only... set all needed values, create needed instances.
          Create another one function like job() where you will make needed job, this function can then return value... Show your widget in this function or do whatever you want....

          God is Real unless explicitly declared as Integer.

          1 Reply Last reply
          0
          • JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by
            #5

            SherifOmran, I suggest you follow this tutorial: http://doc.trolltech.com/4.3/tutorial.html It's good for learning how to use Qt widgets.

            Do you have experience in C++?

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SherifOmran
              wrote on last edited by
              #6

              I am learning by doing my friend

              1 Reply Last reply
              0
              • JKSHJ Offline
                JKSHJ Offline
                JKSH
                Moderators
                wrote on last edited by
                #7

                [quote author="SherifOmran" date="1346324303"]I am learning by doing my friend[/quote]Then I wish you all the best. :) Keep reading, coding, and asking! I recommend the link I posted before -- it's how I learnt Qt.

                What other programming languages do you know? It's helpful to find resources that match your experience, and it will help you learn faster.

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SherifOmran
                  wrote on last edited by
                  #8

                  I know VB :)

                  1 Reply Last reply
                  0
                  • JKSHJ Offline
                    JKSHJ Offline
                    JKSH
                    Moderators
                    wrote on last edited by
                    #9

                    C++ is quite different than VB. It's a lot more powerful too.

                    I tried to find a "C++ tutorial for VB programmers", but couldn't find one, sorry :(

                    Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                    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