Windows, Qt creator (to debug), and Qt Command Line to compile. how do i get the backtrace?
Windows, Qt creator (to debug), and Qt Command Line to compile. how do i get the backtrace?
In Qt Creator, in stead of running the program normally, run the program in the debugger.
When it crashes, go to the stack view (should be the list on the left I think), it should contain the backtrace.
nope, cant see anything![]()
I'm not in front of my computer at the moment so I can't help you with that at the moment.
But to give some more information:
The backtrace is a list of functions that were the last functions being run in your program.
The very last function in this list usually contains the crash. You can then follow the list of functions to see where the problem first occured.
Segmentation faults happen when you try to access memory that you should never access (like the memory segment of the kernel). Most of the time this happens when the pointer to an object is 0.
The stack list should be the list on the left in the debugging section of Qt Creator.
I agree that running in a debugger will be the fastest solution here. Another point: you never check the results of your "find" operation. Despite your insistence that there's a space to be found in the string, it's poor form not to check that the operation actually succeeded.
You could also simply print the results of each line shown to cerr, which would at least isolate the line that is causing the problem. Printing out tmp prior to the string manipulations would also shed some light.
ok i have made something like this:
and then read->append(buffer) and it worked but i commented out the:Qt Code:
if(sscanf(tmp.c_str(), "/join %s", buffer) > 0) {To copy to clipboard, switch view to plain text mode
so its something wrong with them.Qt Code:
To copy to clipboard, switch view to plain text mode
Is there any specific reason that you are using C strings and std::string instead of QString?
Please show us the constructor of Channel.
Qt Code:
{ read->setReadOnly(true); layout->addWidget(read); layout->addWidget(write); layout->addWidget(send); setLayout(layout); setWindowTitle(name.toLatin1()); connect(send, SIGNAL(clicked()), this, SLOT(sendM())); read->append("Welcome to " + name + "\n"); }To copy to clipboard, switch view to plain text mode
buffer is a QString. Print it out and see what it contains before using it.
Or - still by far the best bet - run your code through a debugger and isolate the problem in a minute or two.
Could you print the value of buffer before calling the constructor?
By the way, if you want to extract the argument to your "/join" command, you can do it this way:
Qt Code:
// assuming QString tmp holds the complete line (i.e. "/join #qt") // detect '/' followed by an alphanumeric string followed by a whitespace followed by some other text if(commandRx.exactMatch(tmp)){ // we have found a command cmdName = cmdName.toLower(); if(cmdName == "join") { if(channel.startsWith("#")) { joinChannel(channel.mid(1)); // join everything starting with '#' } } } else if(cmdName == ... ) { ... } ... }To copy to clipboard, switch view to plain text mode
man i already made it to get the text, now when i do something like this:
it works but i need it to append a text in the text edit of the channel, when i call printText (from the channel class) from another function it doesnt do anything:Qt Code:
To copy to clipboard, switch view to plain text mode
any ideas?Qt Code:
Channel *chan = new Channel(this, channel.c_str(), socket, tmp); chan->printText(tmp);To copy to clipboard, switch view to plain text mode
I'm aware of it, the point is you are doing it with a C api that is cumbersome and error prone.
I have no idea what you mean. What is printText(), what other function and what was it supposed to do?it works but i need it to append a text in the text edit of the channel, when i call printText (from the channel class) from another function it doesnt do anything
its to append a text in the "read" text edit
Well, the printText is a function in the "Channel" class when calling it from the "MainWindow" class it doesnt print text in the "read" textEdit, heres what printText supposed to do:
Qt Code:
void Channel::printText(const QString& text) { read->append(text); }To copy to clipboard, switch view to plain text mode
Bookmarks