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. QByteArray losing first element Qt 6.8
QtWS25 Last Chance

QByteArray losing first element Qt 6.8

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 226 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.
  • M Offline
    M Offline
    mishaalnaeemdev
    wrote on 5 Apr 2025, 21:16 last edited by
    #1

    I am facing a weird issue.

    I am using QMetaMethod to get signal signature. Debugging the signal Signature gives the correct value. However, on connect it loses the first letter.

    QMetaMethod signal = metaProperty.notifySignal();
    
    QByteArray signalName = signal.name();
     QByteArray signalSignature = signal.methodSignature();
    
    qDebug() << "Signal name:" << signalName; qDebug() << "Signal signature:" << signalSignature;
    
    connect(obj, signalSignature, this, SLOT(onPropertyChanged()));
    

    This is the output.

    Signal name: "valueChanged" 
    Signal signature: "valueChanged(int)" 
    valueChanged(int) 
    qt.core.qobject.connect: QObject::connect: No such signal cTestDataPoint::alueChanged(int) 
    qt.core.qobject.connect: QObject::connect:  (sender name:   'TestDataPoint_1')
    

    I have also tried using

    const char* signalStr = signalSignature.constData();
    

    and passing the signalStr instead. However, it has the same result. The conversion to char* printed gives correct name too, but on connect it loses first char.

    Any ideas?

    C 1 Reply Last reply 6 Apr 2025, 06:20
    0
    • M mishaalnaeemdev
      5 Apr 2025, 21:16

      I am facing a weird issue.

      I am using QMetaMethod to get signal signature. Debugging the signal Signature gives the correct value. However, on connect it loses the first letter.

      QMetaMethod signal = metaProperty.notifySignal();
      
      QByteArray signalName = signal.name();
       QByteArray signalSignature = signal.methodSignature();
      
      qDebug() << "Signal name:" << signalName; qDebug() << "Signal signature:" << signalSignature;
      
      connect(obj, signalSignature, this, SLOT(onPropertyChanged()));
      

      This is the output.

      Signal name: "valueChanged" 
      Signal signature: "valueChanged(int)" 
      valueChanged(int) 
      qt.core.qobject.connect: QObject::connect: No such signal cTestDataPoint::alueChanged(int) 
      qt.core.qobject.connect: QObject::connect:  (sender name:   'TestDataPoint_1')
      

      I have also tried using

      const char* signalStr = signalSignature.constData();
      

      and passing the signalStr instead. However, it has the same result. The conversion to char* printed gives correct name too, but on connect it loses first char.

      Any ideas?

      C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 6 Apr 2025, 06:20 last edited by
      #2

      @mishaalnaeemdev said in QByteArray losing first element Qt 6.8:

      Any ideas?

      You don't use SIGNAL() macro so you just pass the plain signature to QObject::connect() which is wrong. SIGNAL() and SLOT() are there for a reason...

      https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/kernel/qobjectdefs.h#n52

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3
      • M Offline
        M Offline
        mishaalnaeemdev
        wrote on 6 Apr 2025, 14:38 last edited by
        #3

        I have tried that,

        connect(obj, SIGNAL(signalSignature), this, SLOT(onPropertyChanged()));
        

        but I end up getting

        qt.core.qobject.connect: QObject::connect: Parentheses expected, signal cTestDataPoint::signalSignature
        

        Although, that issue should have been with signal name, not signal signature. Both are giving the same issue

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 6 Apr 2025, 14:46 last edited by Christian Ehrlicher 26 days from now
          #4

          Since it's a compile time macro which combines two constant char arrays it won't work with a non-constant (at compile time) QByteArray. Simply look at the macro what it is doing and do it in your code when you want to do such a strange connect by yourself.
          What are you trying to achieve at all?

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          1
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 6 Apr 2025, 18:05 last edited by
            #5

            Hi,

            Beside the good question of @Christian-Ehrlicher about your use case, if you want to use meta objects, then do it all the way for both signals and slots. That will make your life easier.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0

            1/5

            5 Apr 2025, 21:16

            • Login

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