Skip to content

C++ Gurus

The forum for all discussions in C++ land.
1.3k Topics 8.5k Posts
  • 0 Votes
    3 Posts
    6k Views
    G

    I'm not a namespace expert, but from my understanding:

    QDataStream is in global Namespace (or Qt namespace). So I would try ::QDataStream, as QDataStream would refer to a member within your current namespace.

    Albeit, Andre is correct: Why do you need to implement the operators in the first place?

  • How to ensure comparison operator is "complete"?

    13
    0 Votes
    13 Posts
    5k Views
    A

    I think it's the same one I stumbled upon. ;-)

  • How can I interrupt a function?

    15
    0 Votes
    15 Posts
    12k Views
    N

    All I'm doing is simulating a function that might hang. The following function blocks all timers in all threads in the system until it is finished. If you replace the for loop with while(true), it will block all timers in all threads forever.
    @
    bool HardwareManager::myFunc()
    {
    double a;
    for (int i = 0; i < 100; i++)
    {
    for (unsigned j = 0; j < 10000000; j++)
    {
    a += j * 3.0;
    }
    }

    qDebug() << "finishing myFunc"; return true;

    }
    @

    Edit: please use code tags around code sections; Andre

  • QLocalServer with Win32 pipe

    3
    0 Votes
    3 Posts
    3k Views
    A

    Look the catchcopy explorer plugin code, I have do that's.

  • [SOLVED] capture the output of a class

    5
    0 Votes
    5 Posts
    3k Views
    T

    I played today with the above and i figure it out.

    thanks

  • 0 Votes
    7 Posts
    4k Views
    B

    Maybe you'd like to sg like this:

    @
    #include <iostream>

    using namespace std;

    struct mainStruct
    {
    unsigned char a;
    int b;
    unsigned char c;
    };

    struct sharedStruct
    {
    unsigned char byteValue[75];
    } attribute((may_alias)) ;

    void print(mainStruct* x)
    {
    cout << x->a << endl;
    cout << x->b << endl;
    cout << x->c << endl;
    }

    int main()
    {

    mainStruct ms; //print(&ms); sharedStruct* ss = reinterpret_cast<sharedStruct*>(&ms); ss->byteValue[0] = 22; ss->byteValue[1] = 0; ss->byteValue[2] = 0; ss->byteValue[3] = 0; ss->byteValue[4] = 1; ss->byteValue[5] = 23; ss->byteValue[6] = 1; ss->byteValue[7] = 0; print(reinterpret_cast<mainStruct*>(ss)); return 0;

    }

    @

  • Ocr in c++

    11
    0 Votes
    11 Posts
    18k Views
    M

    I have used Tesseract with Qt and OpenCV (2.04):

    Look at the dlltest project that comes with Tesseract.
    You can make a .so ( or .dll ) to use in your project

    My approach ( which have achieved best results ) is preprocess the
    desired image with text, and pass only the ROIs with the text.

    The result was good but far below commercial packages...

    But, if want to implement your own OCR engine, you must have a good knowledge in all of the following technologies:

    1 - Image segmentation ( OpenCV ??? )
    2 - Feature extraction ( OpenCV ??? )
    3 - Good algorithm for feature grouping
    4 - Text line detection
    5 - Character chopping
    6 - Character recognition ( see Neural Network for Recognition of Handwritten Digits in codeproject )
    7 - Dictionary based context sentece composer ( QRegexp have good support for this )
    8 - Context analyzer

  • Operator aliases not known?

    6
    0 Votes
    6 Posts
    3k Views
    W

    @mlong:
    'not': undeclared identifier

    The compiler doesn't have a token that he can associate with the word 'not'.

    @volker:
    I'm not a 100% sure, though I dont think so. Compiling in C mode would mean that any C++ code that's not C code cannot be compiled. Following this reasoning, then no, I'm not compiling in C mode.

    Also, I'm running the QtCreator standards, which logically would be auto-set to C++. I can't seem to find a switch that would enable the use of operator alternatives.

    I've tried a few compilers on different systems today, and it seems that all compilers running on Windows machine do not normally support the use of alternative operator names (MinGW, MSVC++). The Intel and GNU compilers on Linux (Fedora 15: G++, Scientific 5: Intel) and Mac (Leopard: G++, Intel) do.

    Including the ISO646.h header file solves the problem, albeit not an elegant solution.

  • 0 Votes
    2 Posts
    2k Views
    G

    Being in a Qt forum, I come up with a Qt base solution:

    @
    QString filePath = QString("f/%1/%2/%3/%4/%5")
    .arg(dirHash1)
    .arg(dirHash2)
    .arg(dirHash3)
    .arg(dirHash4)
    .arg(fileName);

    QFileInfo fi(filePath);
    QDir dir = fi.absoluteDir();
    if(!dir.exists())
    dir.mkpath(fi.absoluteDirPath());

    QFile file(filePath);
    @

  • Error handling (try catch)

    2
    0 Votes
    2 Posts
    3k Views
    ZlatomirZ

    The access violation error isn't thrown (exceptions are thrown not errors) - it occurs when you access memory that you don't own.

    Anyway you can initialize your pointers with 0 (null pointer) and then first check for 0 and only then call a member-function (to be a little more safer you can assign 0 to the pointer after you delete it then you detect the attempt to call function after the pointer is deleted)

  • 0 Votes
    7 Posts
    3k Views
    sierdzioS

    Sorry for being so talkative, but here are some further thoughts:

    Once a week is too rare to truly learn programming. I suggest you do more than is required - on your own. Will help you in later years of your study, too. After you get some basics from books/ tutors, get heavily onto building own applications. They don't have to be big or outstandingly functional, but will help you learn (file operations, regular expressions, databases, web interaction etc.).
  • Creating activex control

    5
    0 Votes
    5 Posts
    4k Views
    A

    No, the work must be done by you. Did you start at the documentation of Qt? There is quite a lot of material there, including high-level overviews such as "Building ActiveX servers in Qt" and "Qt's ActiveX Framework (ActiveQt)".

  • Qt4 form MDI, what is it?

    6
    0 Votes
    6 Posts
    4k Views
    B

    This is a helpful example on creating an MDI:
    http://doc.qt.nokia.com/4.7-snapshot/mainwindows-mdi.html

  • 0 Votes
    5 Posts
    4k Views
    S

    "please check this":http://developer.qt.nokia.com/doc/qt-4.8/QTextEdit.html

  • 0 Votes
    4 Posts
    3k Views
    L

    [quote author="Alastor" date="1329746353"]Thank you for your answer.
    I have regenerate my projetc and it's working.[/quote]
    You're welcome.

    [quote author="Alastor" date="1329746353"]
    I really look stupid ..[/quote]
    Nope. Such things just happen - to all of us.

  • Destructor array of object

    24
    0 Votes
    24 Posts
    13k Views
    G

    Use [[Doc:QStringList]] and get rid of memcopy and all the dangerous pointer stuff. It's not necessary here.

  • Wireless Communication

    2
    0 Votes
    2 Posts
    2k Views
    K

    welcome to the forum

    I assume you like to establish a TCP/IP connection using Qt. QTcpSocket and QTcpServer are working independent of the communication means you are using. I am using it on LAN and Wifi. I have no experience using a GSM or other mobile connection. My assumption would be that it will work when the connection is already established.

  • Getting rid of dynamic_cast

    6
    0 Votes
    6 Posts
    5k Views
    L

    Having a single collection containing elements with different interfaces always results in some kind of differentiation at runtime, be it dynamic_cast, QMetaType::type() or a vtable look-up as in the visitor pattern. If you don't want the differentiation at runtime you either have to

    have all the elements in the collection sharing the same interface or have a separate collection for each interface.

    There is no way around that.

    Even when using the visitor pattern your elements have to share the same interface (although a smaller one). I don't know how diverse your BaseKey dervived classes are, but the visitor pattern could at least prevent your base class from beeing the least common multiple of all your derived classes - at the cost of another layer of complexity.

    What is your concern? Performance? Maintainability?

    I possibly would use a combination if I had to eliminate the dependency of a runtime type information system and the complexity of the visitor pattern:
    @
    class IKey
    {
    public:
    enum Action
    {
    BaseAction,
    SpecialAction,
    ...
    };

    virtual void pressKey() = 0; virtual void action(IKey::Action action) = 0;

    };

    class BaseKey : public IKey
    {
    ...
    void action(IKey::Action action)
    {
    switch(action)
    {
    case IKey::BaseAction:
    ...
    break;
    default:
    break;
    }
    }
    };

    class SpecialKey : public BaseKey
    {
    ...
    void action(IKey::Action action)
    {
    switch(action)
    {
    case IKey::BaseAction:
    BaseKey::action(IKey::BaseAction);
    break;
    case IKey::SpecialAction:
    ...
    break;
    default:
    break;
    }
    }
    };

    class BaseClass
    {
    ...
    public:
    void useKeys()
    {
    _useKeys(IKey::BaseAction);
    }

    protected:
    void _useKeys(IKey::Action action)
    {
    IKey* key;
    foreach(key, mKeys)
    {
    key->pressKey();
    key->action(action);
    }
    }
    };

    class DerivedClass : public BaseClass
    {
    public:
    void useKeys()
    {
    _useKeys(IKey::SpecialAction);
    }
    };
    @
    Brain to terminal. Not tested. Exemplary.

    The switch can be replaced with a condition if every key needs to implement just one action. Won't win a design price, but I haven't seen a compromise yet that does.

    [quote author="bkamps" date="1329295734"]I have also seen other 'solutions' that override the mKeys members in the derived: QVector<SpecialKey*> mKeys.[/quote]

    You cannot overload or override member variables in dervied classes, you just hide them - and you end up with two seperate member variables.

  • GoingNative 2012 VoD

    1
    0 Votes
    1 Posts
    1k Views
    No one has replied
  • OCX or .h +.lib + .dll&#63;

    4
    0 Votes
    4 Posts
    3k Views
    K

    I tried your approach but i get the following error when i try to do this

    @ int x = OpenComFiscal (1, 1);
    qDebug () << x;
    @

    the function is recognised by the editor and I have the DLL inside the folder that contains my app .exe

    I also included the path to the source (the header) and added to the LIBS variable of my .pro file the library. It`s like the DLL is not functioning

    //----------------------------------------------

    Added
    @#include "windows.h"@

    and compiles. The thing is that im concerned about what you said. Whats are the risks of using this lib? how can I be sure it wont brake?