Sweet mother of Jesus, I figured it out. My problems were that a) I didn't at first realize that when you move a class instance to a new thread, you don't move its members, that has to be done separately, and b) you can't use moveToThread at all on a QLocalSocket. According to the warning message I got, my QLocalSocket instance had children, and you can't move an object with children. However I never created an object with my_local_socket as a parent, nor did I see such in the corresponding moc file. As a result QLocalSocket stayed in the gui thread, and I got the results I did. Here's code that actually works (knock on wood):

Qt Code:
  1. //include file declaring MyObject
  2.  
  3. class MainWindow : public QGLWidget //The fact that I'm using GL here is not important
  4. {
  5. Q_OBJECT
  6.  
  7. MainWindow(QGLWidget* parent)
  8. ...
  9.  
  10. signals:
  11. void ConnectSocket();
  12. ...
  13.  
  14. public slots:
  15. //... various slots
  16. ...
  17.  
  18. private:
  19. MyObject* my_object;
  20. };
  21.  
  22. MainWindow::MainWindow
  23. {
  24. QThread* thd = new QThread();
  25. my_object = new MyObject(this); //main_window is not the parent of my_object, it's a receiver
  26. my_object->moveToThread(thd);
  27. cerr << "GUI thread: " << thread() << endl;
  28. cerr << "Object thread: " << thd << endl;
  29. cerr << "my_object thread: " << my_object->thread() << endl;
  30. thd->start();
  31.  
  32. connect(this, SIGNAL(ConnectSocket()), my_object, SLOT(ConnectSocket()), Qt::QueuedConnection);
  33. //I think this maneuver is the *only* way to ensure the QLocalSocket instance is in the worker thread.
  34. emit ConnectSocket();
  35. }
  36.  
  37.  
  38. class MyObject : public QObject
  39. {
  40. Q_OBJECT
  41.  
  42. public:
  43. MyObject(MainWindow* _gui);
  44.  
  45. signals:
  46. ...
  47. //various signals sent to the MainWindow instance
  48.  
  49. public slots:
  50. void ConnectSocket();
  51. void ReadyRead();
  52. void LostConnection();
  53. void SocketError(QLocalSocket::LocalSocketError err);
  54.  
  55. private:
  56. MainWindow* gui;
  57. QLocalSocket* my_local_socket;
  58. };
  59.  
  60. MyObject::MyObject(MainWindow* _gui) : gui(_gui)
  61. {
  62. }
  63. void MyObject::ConnectSocket()
  64. {
  65. bool b(true);
  66. my_local_socket = new QLocalSocket();
  67. my_local_socket->connectToServer("my_local_server", QLocalSocket::ReadOnly);
  68. cerr << "my_local_socket thread: " <<my_local_socket->thread() << endl;
  69. b &= connect(my_local_socket, SIGNAL(readyRead()), this, SLOT(ReadyRead()));
  70. b &= connect(my_local_socket ,SIGNAL(error(QLocalSocket::LocalSocketError)),this, SLOT(SocketError(QLocalSocket::LocalSocketError)));
  71.  
  72. b &= connect(this,SIGNAL(my_object_signal()), gui, SLOT(gui_slot()), Qt::QueuedConnection);
  73. // ... and several more of these
  74.  
  75. cerr << "Connect success, MyObject::ConnectSocket: " << b << endl;
  76. }
To copy to clipboard, switch view to plain text mode 

The cerr statements output what they should; my_object and my_local_socket are in the worker thread, not the gui thread, and the connection is a success.

Matt