Important: Please read the Qt Code of Conduct -

[Solved] qRegisterMetaType?

  • Hello friends.
    im beginner in Qt & im creating an application with winpcap. During running the application, i got an strange result!!!
    something like this:

    " 5.2.1-x86-msvc2012-opengl\include\QtCore/qmetatype.hrmalizedMetaTypeizedMetaTypeo
    gl\include\QtCore/qmetatype.he name, please call qRegisterMetaType instead.a not normalized type name, please call qRegisterMetaType instead. "

    The result must be an IP address not the above result!!!
    in my codes, i used a thread to capture the packets & used this signal & slot:

    connect(tCapture, SIGNAL(SendData(const u_char *)), this, SLOT(ReceiveData(const u_char *)));

    Thanks a lot.
    Ya Ali.

  • You can safely remove the const, even if the real signature of SendData and ReceiveData is const u_char*.
    Since you're passing the parameter via a pointer you don't need to register the type AFAIK.

  • Thanks dear Johan Solo.
    i removed the const but the starnge results are still there!

  • Not sure if I can help but for the sake of clarity, you get this as a compilation error?

    Could you please post the exact line the error refers to and the complete error message? (the post you have cuts some lines in the middle).

  • Hello frankiefrank.
    this is the whole of my project:
    (click the orange picture that is written download in order to download this file)

    I thinks this is a logical error.
    In application output it shows something like this:

    QObject::connect: Cannot queue arguments of type 'QList<QPersistentModelIndex>'
    (Make sure 'QList<QPersistentModelIndex>' is registered using qRegisterMetaType().)
    QObject::connect: Cannot queue arguments of type 'QVector<int>'
    (Make sure 'QVector<int>' is registered using qRegisterMetaType().)

    As you said, the error i mentioned in my first post is not complete, because the application doesn`t show

  • I can't really run your code without the pcap.h file.

    From a first look, you don't emit your signal correctly. It should be:
    emit SendData(packetData);

    Also, I'm not sure if you should even call qRegisterMetaType there, the error you get seem to be not relevant to the parameters we actually see.

  • Thanks for your response.
    i corrected emit SendData(packetData); but the error is still there.

    I searched & some users of some forums said you shouldnt pass reference parameter in signal & slot. Im a little confused!

  • For your connect() call, add a boolean variable to store the return value of the connect call (i.e. bool success = connect(....) ).

    Then run with debug, make a break point on the connect line.

    Make sure that before you pass that line, your Application Output doesn't show any errors. Then step through the line and assure that you really get that error about QList<QPersistentModelIndex> only then. If it appeared even before that - then it's from somewhere else in the code you are compiling/running and has nothing to do with this specific connect.

  • i wrote:
    bool checked = connect(tCapture, SIGNAL(SendData(const u_char *)), this, SLOT(ReceiveData(const u_char *)));

    checked --> true

    i think The mentioned error appear when data transfer from tCapture thread to mainwindow class. but not sure.

  • OK, it's a bit difficult to help out if you don't localize the error first through the debugging.

    In the code that you sent me the connect statement contained Qt::DirectConnection - this doesn't make sense since you will be emitting the signal from a different thread.

    Again, try commenting out the qRegisterMetaType call and try to localize the error (or is this a warning only?) through debugging.

    For example, put a breakpoint inside your slot to see that you actually get to that code, then keep stepping through to see at which point that warning/error appears.

  • frankie frank.
    I think the problem is solved.
    as you said not relate to connect. That`s because of my slot function.
    i had written something like this:
    QString a = ih->daddr.byte4;
    newRow = new QStandardItem(a);

    it means i set u_char to Qstring directly! this was my wrong!

    thanks to you because of your help.
    (excuse me if my english writting was not good)

  • No worries :) Glad to have helped.

    Make sure you edit your original post and add [SOLVED] to the post title.

Log in to reply