Results 1 to 14 of 14

Thread: Get text from QCombobox.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Posts
    115
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanked 1 Time in 1 Post

    Default Get text from QCombobox.

    Hello Anyone,

    I have qt-4.7

    I have a Mainwindow with QComboBox called diaCombobox.
    I have also severall QDialogs.
    Now i want to retrieve text from my MainWindow QComboBox (diaCombobox) en paste into my QDialog.
    How can i connect to my MainWindow from my QDialog to get the text from my MainWindow QCombobox (diaCombobox).

    mainwindow.h
    Qt Code:
    1. class MainWindow : public QMainWindow
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. MainWindow(QWidget *parent = 0);
    7. ~MainWindow();
    8. QComboBox *diaCombobox;
    9. etc..
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cc
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6.  
    7. diaCombobox = ui->diaCombobox;
    8. etc....
    To copy to clipboard, switch view to plain text mode 

    dialog.h
    [CODE]
    class SlotDialog : public QDialog
    {
    Q_OBJECT

    public:
    SlotDialog(QWidget *parent = 0);
    //int n;
    //QString ae;
    //QString vc;
    //QString voed;
    ~SlotDialog();

    public slots:
    void changed();

    private:
    Ui::SlotDialog *ui;
    MainWindow *parent;
    QTableWidget *slotTable;
    etc...
    [CODE]

    dialog.cc
    Qt Code:
    1. SlotDialog::SlotDialog(QWidget *parent) :
    2. QDialog(parent),
    3. ui(new Ui::SlotDialog)
    4.  
    5. {
    6. ui->setupUi(this);
    7. connect(ui->slotTable, SIGNAL(cellClicked(int,int)), this, SLOT(changed()));
    8. }
    9.  
    10. etc..
    To copy to clipboard, switch view to plain text mode 

    thanks in advanced.

  2. #2
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    33
    Thanked 10 Times in 10 Posts

    Default Re: Get text from QCombobox.

    this->ui->comboBox->currentText ();

    greetings

  3. #3
    Join Date
    Jan 2006
    Posts
    115
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanked 1 Time in 1 Post

    Default Re: Get text from QCombobox.

    Hello,

    this->ui->comboBox->currentText ();

    This give my a error because in my QDialog i don't have a QCombobox.
    Only in my MainWindow.

    dialo.cc
    Qt Code:
    1. SlotDialog::SlotDialog(QWidget *parent) :
    2. QDialog(parent),
    3. ui(new Ui::SlotDialog)
    4.  
    5. {
    6. ui->setupUi(this);
    7. connect(ui->slotTable, SIGNAL(cellClicked(int,int)), this, SLOT(changed()));
    8. }
    9.  
    10. this->ui->comboBox->currentText (); this is pointing to my connect ().
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Get text from QCombobox.

    It really depends on exactly what you want to achieve and how the objects are create/related.

    Here are some options that rely only on standard C++:
    • Put a public getter method in your QMainWindow sub-class and call that from the dialog code
    • Put a public setter method in your QDialog sub-class and call that from the main window code at appropriate times.
    • Pass the value of the combo box into the dialog at construction


    This uses Qt:
    • Connect the "void currentIndexChanged ( const QString & text )" signal of the combo box to a receiving slot in the dialog.

Similar Threads

  1. Highlight an item in QCombobox by text color
    By AlekseyK in forum Qt Programming
    Replies: 6
    Last Post: 18th March 2019, 21:31
  2. Replies: 2
    Last Post: 28th April 2011, 14:43
  3. How to set Text Elide Mode for QComboBox
    By kalos80 in forum Qt Programming
    Replies: 1
    Last Post: 27th February 2011, 08:42
  4. How to use rich text in a QComboBox?
    By aarunt1 in forum Qt Programming
    Replies: 3
    Last Post: 19th March 2010, 20:20
  5. QComboBox with fixed text?
    By squidge in forum Qt Programming
    Replies: 0
    Last Post: 14th November 2009, 21:39

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.