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. QUiLoader with signals and slots
Forum Updated to NodeBB v4.3 + New Features

QUiLoader with signals and slots

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 2.0k 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.
  • E Offline
    E Offline
    Exotic_Devel
    wrote on last edited by
    #1

    My project is all based on QUiLoader, ie, all interfaces are generated dynamically.
    I created a form with Qt Creator for the user to enter the parameters for the database connection. When clicked [OK] data from QLineEdit should be passed to the QSettings object. How to using signals and slots with QUiLoader?

    Below, my methods of reading and writing settings. writeSettings calls the settings form.

    @QHash DataAccess::readSettings()
    {
    QSettings connecsettings( QSettings::IniFormat, QSettings::SystemScope, "Freedom", "TecTracker");

    QHash<QString, QVariant> *parameter = new QHash<QString, QVariant>();

    connecsettings.beginGroup("Connection");

    if(!connecsettings.contains("host"))
    writeSettings(&connecsettings);

    parameter->insert("host", connecsettings.value("host", "127.0.0.1"));
    parameter->insert("port", connecsettings.value("port", 5432);
    parameter->insert("database", connecsettings.value("database"));
    parameter->insert("user", connecsettings.value("user", "postgres"));
    parameter->insert("passw", connecsettings.value("passw", "postgres"));

    connecsettings->endGroup();

    return parameter;
    }

    void DataAccess::writeSettings(QSettings* settings)
    {
    DynamicQtWidgets* guigenerator = new DynamicQtWidgets("configconnec.ui", this);
    QDialog *confconnec = guigenerator->createWidget();
    confconnec->show();
    }@

    Searching the forum I found a similar "topic":http://qt-project.org/forums/viewthread/31605. but the answers did not help me. There is an answer stating that signals and slots can be implemented in the ui file. How to do this with Qt Creator? Would be in the "Signals & Slots Editor" tab of the designer mode?

    !http://i58.tinypic.com/2mgw3l0.png(Signals & Slots Editor)!
    ?

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2
      1. Get the reference of lineEdit and Button(which you click ok)
      2. Write your own slot in your own class file
      3. Connect the either lineEdit or Button signal with your slot defined in Step#2,
      4. Inside your slot, do whatever the custom logic required

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      1
      • E Offline
        E Offline
        Exotic_Devel
        wrote on last edited by
        #3

        It is not possible to do this in the ui file? Ie I create the slot in my class, but the connection to the signal leaving in the ui file?

        Something like

        @ <sender>qdbb_okcancel</sender>
        <signal>accept()</signal>
        <receiver>MyClass</receiver>
        <slot>setSettings()</slot>@

        I wanted to avoid manipulation of the GUI in code

        V 1 Reply Last reply
        0
        • E Exotic_Devel

          It is not possible to do this in the ui file? Ie I create the slot in my class, but the connection to the signal leaving in the ui file?

          Something like

          @ <sender>qdbb_okcancel</sender>
          <signal>accept()</signal>
          <receiver>MyClass</receiver>
          <slot>setSettings()</slot>@

          I wanted to avoid manipulation of the GUI in code

          V Offline
          V Offline
          VoLinhTruc
          wrote on last edited by VoLinhTruc
          #4

          @Exotic_Devel
          I have the same demand as your (save signal and slot into ui file) but sadly,
          I tried to make a connection of "button clicked" dignal to a slot but there are no change in *.ui file.
          The change affect to the source code, not on *.ui file.

          JonBJ 1 Reply Last reply
          0
          • V VoLinhTruc

            @Exotic_Devel
            I have the same demand as your (save signal and slot into ui file) but sadly,
            I tried to make a connection of "button clicked" dignal to a slot but there are no change in *.ui file.
            The change affect to the source code, not on *.ui file.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @VoLinhTruc
            I do not use "auto connection from Designer", but so far as I am aware that works by naming the slots correspondingly to the signals, and then having a single call in the source code to void QMetaObject::connectSlotsByName(QObject *object). See https://doc.qt.io/qt-5/qobject.html#auto-connection and https://doc.qt.io/qt-5/designer-using-a-ui-file.html#automatic-connections. This means there will nothing in the .ui file for the connection, it will be done by name during initialisation of the designed widget.

            1 Reply Last reply
            1

            • Login

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