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. Array not sent from signal and slot
QtWS25 Last Chance

Array not sent from signal and slot

Scheduled Pinned Locked Moved Solved General and Desktop
qtcreatorsignal & slotarraysend
3 Posts 2 Posters 2.4k Views
  • 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.
  • L Offline
    L Offline
    Lasith
    wrote on 17 Sept 2017, 13:55 last edited by Lasith
    #1

    I want to send an array from one form(MainWindow) to another form(Dialog) upon a button click! Though the array seems to be sent it returns a wrong value! Following are my codes!

    MainWindow.h

    signals:void sendArray(int a[]);

    MainWindow.cpp

    void MainWindow::on_pushButton_clicked()
    {
    int a[] = {1,2,3};
    Dialog dialog1;
    connect(this,SIGNAL(sendArray(int[])),&dialog1,SLOT(receiveArray(int[])));
    emit sendArray(a);

    dialog1.exec();
    

    }

    Dialog.h
    public slots:
    void receiveArray(int a[]);

    Dialog.cpp

    void Dialog::receiveArray(int a[]){
    int value=a[0];
    QString value1=QString::number(value);
    ui->label->setText(value1);
    }

    When the program is run(no compile errors occur) and the button is clicked though 1 (0th index of the array) should printed on the label in Dialog form a wrong value 8441124 is printed. How can I correct this?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      Lasith
      wrote on 17 Sept 2017, 17:24 last edited by
      #2

      I found the solution myself! Use QList<int> instead of normal arrays :)

      M 1 Reply Last reply 18 Sept 2017, 06:23
      0
      • L Lasith
        17 Sept 2017, 17:24

        I found the solution myself! Use QList<int> instead of normal arrays :)

        M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 18 Sept 2017, 06:23 last edited by
        #3

        @Lasith
        Hi
        old type c array can also work.
        Its just a matter of what is registered already.
        You can register your own types.

        http://doc.qt.io/qt-5/qmetatype.html#Q_DECLARE_METATYPE

        1 Reply Last reply
        0

        1/3

        17 Sept 2017, 13:55

        • Login

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